PyDocs

Nav

Generic Operating System Services

makedirs

os

function (source)
  • makedirs(name, mode=0o777, exist_ok=False, *, parent_mode=None)
makedirs(name [, mode=0o777][, exist_ok=False][, parent_mode=None])

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
directory already exists, raise an OSError if exist_ok is False.
Otherwise no exception is raised.  If parent_mode is not None, it will
be used as the mode for any newly-created, intermediate-level
directories. Otherwise, intermediate directories are created with the
default permissions (respecting umask).  This is recursive.
Changed in 3.2, 3.4.1, 3.6, 3.7, 3.15
  • 3.2: Added the exist_ok parameter.
  • 3.4.1: Before Python 3.4.1, if exist_ok was True and the directory existed, makedirs() would still raise an error if mode did not match the mode of the existing directory. Since this behavior was impossible to implement safely, it was removed in Python 3.4.1. See bpo-21082.
  • 3.6: Accepts a path-like object.
  • 3.7: The mode argument no longer affects the file permission bits of newly created intermediate-level directories.
  • 3.15: The parent_mode parameter. To match the behavior from Python 3.6 and earlier (where mode was applied to all created directories), pass parent_mode=mode.
0 Examples
No examples for os/makedirs.
See Also
No see-alsos for os/makedirs
0 Notes
No notes for makedirs