Entry
How do I check to see if a file exists?
Jun 13th, 2000 20:12
unknown unknown, Peter Schneider-Kamp
To check if a file exists use:
>>> import os.path
>>> os.path.exists("python/")
1
>>> os.path.exists("spam/")
0
>>> os.path.exists("python/patches/submitted/array.pop-extend.patch")
1
If you only want a true for regular files have a look at isfile():
>>> os.path.isfile("python/")
0
>>> os.path.isfile("spam/")
0
>>> os.path.isfile("python/patches/submitted/array.pop-extend.patch")
for more info or other function look at:
http://python.org/doc/current/lib/module-os.path.html