Use Path.is_dir() to check whether a path points to a directory. It returns False for a missing path or a path to a regular file, unlike Path.exists(), which can be true for either. If your code already uses os.path, use os.path.isdir() instead.
Check a directory with pathlib
pathlib is a clear choice for modern Python code, especially when you already work with Path objects:
from pathlib import Path
folder = Path("/path/to/check")
if folder.is_dir():
print("Directory exists")
else:
print("Directory does not exist")
Path.is_dir() asks whether the path points to a directory, not merely whether an entry exists at that path. The Python 3.12 pathlib documentation says it returns true for a directory or a symbolic link pointing to one, and false for another kind of file.
Use os.path.isdir() in os.path-based code
If the surrounding code uses string paths and os.path helpers, os.path.isdir() provides the same directory-specific check:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute#1 Best Overall
import os
folder = "/path/to/check"
if os.path.isdir(folder):
print("Directory exists")
else:
print("Directory does not exist")
Python documents os.path.isdir() as checking whether a path is an existing directory. It follows symbolic links. Path-like objects have been accepted since Python 3.6.
Choose the check that fits your code
| Check | Best fit | What it checks | Symbolic links |
|---|---|---|---|
Path(path).is_dir() |
Code using pathlib or Path objects |
Whether the path points to a directory | Follows the link to its target by default |
os.path.isdir(path) |
Code already using os.path or string-based path helpers |
Whether the path points to an existing directory | Follows the link to its target |
Both are standard-library options; the surrounding path-handling style is usually the simplest deciding factor. Neither should be confused with a general existence check.
Rank #2
Why Path.exists() is not enough
Path.exists() returns true if a file or directory exists at the path. It does not establish that the entry is a directory. Use is_dir() when the type matters:
path = Path("/path/to/check")
if path.exists():
print("Something exists here")
if path.is_dir():
print("It is a directory")
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Symlinks, missing paths, and error behavior
Symbolic links
Both common checks follow symbolic links by default. A symlink to a directory passes; a broken symlink does not. The follow_symlinks option for Path.is_dir() was added in Python 3.13, so do not rely on that option when supporting earlier versions. See the versioned Python 3.12 pathlib reference for the documented default behavior.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Missing paths and paths that are not directories
A missing path, a broken symlink, or a path to another file type does not pass the directory check. In the Python 3.12 documentation, Path.is_dir() returns false for these cases.
Inaccessible paths and Python version differences
Error handling depends on the Python version. The Python 3.12 documentation says errors other than the ordinary non-directory cases, including permission errors, can propagate. The Python 3.15 prerelease documentation records a change made in Python 3.14: pathlib status checks return false for invalid, inaccessible, or missing paths instead of raising OSError. If your program needs to tell an inaccessible path from a missing one, inspect it with Path.stat() and handle the relevant errors explicitly.
Quick Recap
Best Value
Practical choice
- Use
Path(path).is_dir()forpathlib-based code and modern path composition. - Use
os.path.isdir(path)when it fits the helpers already used in your codebase. - Use
Path.exists()only when you need to know whether some filesystem entry exists, regardless of whether it is a file or directory. - Account for your supported Python versions if inaccessible paths must be distinguished from missing ones.
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.




