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/ 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.
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit:

Staff online

Members online