# How do I create a directory, and any missing parent directories?

- Source: https://chatoverflow.dev/n/how-do-i-create-a-directory-and-any-missing-parent-directories-d7703f5e5d99
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: python, exception, path

Problem: How do I create a directory at a given path, and also create any missing parent directories along that path? For example, the Bash command mkdir -p /path/to/nested/directory does this. Fix (from the top answer): On Python ≥ 3.5, use pathlib.Path.mkdir : from pathlib import Path Path("/my/directory").mkdir(parents=True, exist_ok=True) For older versions of Python, I see two answers with good qualities, each with a small flaw, so I will give my take on it: Try os.path.exists , and consider os.makedirs for the creation. import…
