Use Path("report.csv").exists() to check whether a path points to something that exists. It returns true for both files and directories. If you need to confirm that the path is a regular file, use Path("report.csv").is_file() instead.
Check whether a path exists with pathlib
pathlib is a clear choice for new Python code. Create a Path object, then call exists():
from pathlib import Path
path = Path("report.csv")
if path.exists():
print("The path exists")
This check includes directories as well as files. For example, Path("reports").exists() can be true even if reports is a directory. The Python 3.14 pathlib documentation defines exists() as checking whether a path points to an existing file or directory.
Check that the path is a regular file
If a directory should not count, use is_file():
from pathlib import Path
if Path("report.csv").is_file():
print("It is a regular file")
is_file() is the more precise predicate when your code needs a regular file rather than any existing path. It returns false for a directory.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
Choose between pathlib and os.path
Python’s standard library provides procedural alternatives in os.path. Choose the predicate that matches what you mean:
| What you need to check | pathlib | os.path |
|---|---|---|
| Any existing file or directory | Path(path).exists() |
os.path.exists(path) |
| A regular file | Path(path).is_file() |
os.path.isfile(path) |
Use pathlib when you want to work with a Path object and continue using its path operations. Use os.path when the surrounding code already follows that style. The Python os.path documentation notes that isfile() follows symbolic links and accepts path-like objects.
Rank #2
Understand symbolic links and false results
By default, Path.exists() and Path.is_file() follow symbolic links: they test the link’s target. In Python 3.12 and later, Path.exists(follow_symlinks=False) checks whether the path itself exists without following a symbolic link.
A false result does not always mean that a path is simply absent. The Python 3.14 pathlib documentation says exists() returns false for invalid, inaccessible, or missing paths. If your program needs to tell those cases apart, call stat() and handle the filesystem errors it raises.
Account for Python version differences
Python 3.14 changed Path.exists(), Path.is_file(), and several related query methods: they now return false instead of raising operating-system OSError exceptions. Earlier Python versions could raise some errors and suppress others, so do not assume error behavior is identical across versions. Use stat() when the reason a lookup failed matters.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




