• We did not send an email asking for donations - please read this post.

check file Existing with Python Script


Well-Known Member
Mar 9, 2020
Reaction score
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!

Linux.org Hosting Donations
Consider making a donation

Staff online

Members online