check file Existing with Python Script



W

warlockk

Guest
You can use the path.exists () method when you want to check if a file or folder exists.

Screenshot-2020-4-20 Python Os Modülü(1).png


I first searched the / home folder and got the answer True, then I searched /home/sinan.py and got the False answer because there was no such file.

You can also query whether the parameter you provided is a directory or a file. For this, we use the path.isdir () and path.isfile () methods.

Screenshot-2020-4-20 Python Os Modülü.png


In the example, I questioned an existing folder and a non-existent folder. Then I questioned an existing file and a non-existent file, I was able to successfully see the values of True and False.
 

Members online

No members online now.

Top