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

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

$
0
0
import os# for testing purpose args defaulted to current folder & file. # returns True if file founddef file_exists(FOLDER_PATH='../', FILE_NAME=__file__):    return os.path.isdir(FOLDER_PATH) \        and os.path.isfile(os.path.join(FOLDER_PATH, FILE_NAME))

Basically a folder check, then a file check with proper directory separator using os.path.join.


Viewing all articles
Browse latest Browse all 46

Trending Articles



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