all Python 3osfunction
os.path.isdir
os.path — existence and type checks
Check whether a path exists and is a directory.
Syntax
os.path.isdir(path)
A False answer merges two cases: the path is missing, or it exists but is a file. Ask exists separately when the difference matters. A symlink to a directory counts as a directory. Checking before creating is a race: instead of if not isdir(p): mkdir(p) write os.makedirs(p, exist_ok=True).
Examples
import os
print(os.path.isdir(os.path.dirname(os.__file__))) # → True
print(os.path.isdir('/tmp')) # → True
print(os.path.isdir('/etc/hosts')) # → False (это файл)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy