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

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

$
0
0

You have the os.path.exists function:

import os.pathos.path.exists(file_path)

This returns True for both files and directories but you can instead use

os.path.isfile(file_path)

to test if it's a file specifically. It follows symlinks.


Viewing all articles
Browse latest Browse all 47

Latest Images

Trending Articles



Latest Images

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