How to Check File or Directory Exists in Python
279
If you would like to check if a File or Directory exists with Python, it's very simple to do by importing "os" library and "os.path.exists" funtion in Python.
Codes below will print "True" or "False".
import os
path = 'file/filename.txt'
result = os.path.exists(path)
print(result)
path = 'file/filename.txt'
result = os.path.exists(path)
print(result)
If you are looking for consultation, fill the Contact Form below.
My brain is only a receiver, in the Universe there is a core from which we obtain knowledge, strength and inspiration.
Haluk YAMANER
Founder @ Future Software UAE
Founder @ Future Linux
Click here for more about me »