0
print(os.path.isdir("~/.my_dir"))

the command should return True, if exists, and False, if not. Anyways, it returns False if specified folder exists, or does not.


dir = os.path.isdir('/.databases')
dirfile = os.path.exists('~/.databases/database.db')

if (dir == False):
    os.system('mkdir ~/.databases')
elif (dir == True):
    if dirfile == False:
        os.mknod('~/.databases/database.db')
        start()
    elif dirfile == True:
        db = ("~/.databases/database.db")
        main(db)
    else:
        print('Error 1')
else:
    print('Error 2')

That's the code i've been trying to fix for now 2 hours. it returns following error:

mkdir: cannot create directory ‘/home/username/.databases’: File exists

Again, the problem is, that the command returns False whenever it needs to be True.

2 Answers2

0

You are missing the ~ from the first path.

It should be:

dir = os.path.isdir('~/.databases')

You can also simplify your if/else:

if os.path.isdir('~/.databases'):
    print('dir')
else:
    print('not dir')
Balázs
  • 496
  • 3
  • 8
0

Try this:

import os
dir = os.path.isdir('~/.databases')
dirfile = os.path.isfile('~/.databases/database.db')

if dir:
    if dirfile:
        db = ("~/.databases/database.db")
        main(db)
    else:
        os.mknod('~/.databases/database.db')
        start()
else:
    os.mkdir('~/.databases')