Quantcast
Channel: How do I check whether a file exists without exceptions? - Stack Overflow
Viewing all articles
Browse latest Browse all 46

Answer by codelox for How do I check whether a file exists without exceptions?

$
0
0
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.


Viewing all articles
Browse latest Browse all 46

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>