check file Existing with Python Script



warlockk

Well-Known Member
Joined
Mar 9, 2020
Messages
453
Reaction score
277
Credits
1,727
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.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top