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

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

$
0
0

The easiest way to do this is with

import osif os.path.exists(FILE):  # file exists  passelse:  # file does not exists  pass

from the os library, while FILE is the relative path. In Windows this may or many not work and you may have to use the absolution path by doing os.path.exists(os.path.join(os.path.abspath('./'), FILE)), where FILE is still the relative path plus file name


Viewing all articles
Browse latest Browse all 46

Trending Articles



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