Python Create Directory with Missing Parents (mkdir -p Equivalent)
How do I create a directory at a given path, including any missing parent directories, similar to mkdir -p /path/to/dir in Bash?
Python Create Directory with Missing Parents mkdir -p Equivalent
coldshadow44 on 2025-10-13
Make a comment
_
2025-10-14
The pathlib module provides an elegant, object-oriented way:
Python 3.2+ – Using os.makedirs
Python <3.2 – Safe Approach
Older versions don’t have exist_ok, so you need to handle the exception manually:
Best Practice
This approach works reliably across different Python versions and ensures nested directories are created safely.