On this page
  1. os.makedirs
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

os.makedirs

Prev: os.lstat | Up: os | Next: os.mkdir
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.makedirs
Tags: #public #python3 #stdlib #os


Import

import os
from os import makedirs

Signature & Overview

os.makedirs(name, mode=511, exist_ok=False)

Super-mkdir; create a leaf directory and all intermediate ones. Works like mkdir, except that any intermediate path segment (not just the rightmost) will be created if it does not exist. If the target

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    nested = Path(tmp) / "a" / "b" / "c"
    os.makedirs(nested, exist_ok=True)
    assert nested.is_dir()

Gotchas

REPL Inspect

from os import makedirs
help(makedirs)

Linked from

Related notes