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

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

$
0
0

Another possible option is to check whether the filename is in the directory using os.listdir()

import osif 'foo.txt' in os.listdir():    # Do things

this will return true if it is and false if not


Viewing all articles
Browse latest Browse all 46

Trending Articles



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