all Python 3osfunction
os.mkdir
os — directories
Create a single directory at the given path.
Syntax
os.mkdir(...)
It creates exactly one level: a missing parent raises FileNotFoundError — a chain of directories needs os.makedirs. An existing directory raises FileExistsError. The mode passes through the process umask: mkdir(p, 0o777) with the usual umask 022 creates a directory with 0o755.
Examples
import os
base = 'mkdir_demo'
os.mkdir(base)
d = os.path.join(base, 'sub')
os.mkdir(d)
print(os.path.isdir(d)) # → True
os.rmdir(d)
os.rmdir(base)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy