0

When i try to check if a file exists making use of the pathlib.Path method ".exists()" or "is_file()" what i get is False.

home = pathlib.Path.home()

path1 = home / r"Desktop\Python 3\Libro de Python3\my_directory\file1.txt"
path2 = home / r"Desktop\Python 3\file2.txt"
print(path1.exists())
print(path1.is_file())
print(path1.parent)

print("")

print(path2.exists())
print(path2.is_file())
print(path2.parent)

The output is:

False
False
C:\Users\Carlos\Desktop\Python 3\Libro de Python3\my_directory

True
True
C:\Users\Carlos\Desktop\Python 3

Why am i getting False for path1? is it because the path is too large?.

And yes, the file exists.

Heijs7
  • 27
  • 6
  • Can you share output of tree or dir command to verify if path is 100% correct. – Maciek May 01 '20 at 17:19
  • 1
    Please check if this command will be successful from your cmd: ```notepad C:\Users\Carlos\Desktop\Python 3\Libro de Python3\my_directory\file1.txt``` – Maciek May 01 '20 at 17:29
  • The command opens the file correctly and the program return True now... – Heijs7 May 01 '20 at 17:33

0 Answers0