Why does os.path.isfile return False?

When you print os.path.isfile(i), you’re checking if “1.txt” or “2” or “3.txt” is a file, whereas when you run os.path.isfile("/home/user/Desktop/1/1.txt") you have a full path to the file.

Try replacing that line with

print(os.path.isfile("/home/user/desktop/1/" + i))

Edit:

As mentioned in the comment below by icktoofay, a better solution might be to replace the line with

print(os.path.isfile(os.path.join("/home/user/desktop/1", i)))

or to earlier store “/home/user/desktop/1” to some variable x, allowing the line to be replaced with

print(os.path.isfile(os.path.join(x,i)))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)