How to Check if a File Exists in Python - Qvault
qvault.io › python › file-exists-pythonDec 08, 2021 · from pathlib import Path path_exists = Path.exists ( "home/dir/file.txt" ) if path_exists: print ( "found it!" ) else : print ( "not found : (") Code language: Python (python) Notice that path_exists will be True whether this is a file or a directory, it’s only checking if the path exists. Note: On older versions of Python you may not have ...