How do I check if a file exists or not, without using the try statement?
import os
#Your path here e.g. "C:\Program Files\text.txt"
#For access purposes: "C:\\Program Files\\text.txt"
if os.path.exists("C:\..."):
print "File found!"
else:
print "File not found!"
Importing os
makes it easier to navigate and perform standard actions with your operating system.
For reference also see How to check whether a file exists using Python?
If you need high-level operations, use shutil
.