check file Existing with Python Script



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.
 
Are there any way to check the file existence in Python script.
I'm confused... Do you want to create an infinite loop in bash as per the title of your post?! Or check for a file in python?! Or both?!
 

Staff online


Top