@@ -91,20 +91,31 @@ def copytree(src, dst, symlinks=False, ignore=None):
9191 return shutil .copy2 (s , d )
9292
9393
94- def maybe_make (directory ):
94+ def maybe_make (directory , mode = 0o777 , parents = False , exist_ok = False ):
9595 """
96- Makes a directory only if it doesn't already exist
97-
96+ Create a directory at this given path, but only if the directory does
97+ not already exist.
98+
9899 :param directory: Directory to create
99100 :type directory: str or pathlib.Path
100-
101+ :param mode: Combined with the process’ umask value to determine the file mode and access flags
102+ :type mode:
103+ :param parents: If ``False`` (the default), a missing parent raises a :class:`~python:FileNotFoundError`.
104+ If ``True``, any missing parents of this path are created as needed; they are created with the
105+ default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
106+ :type parents: bool
107+ :param exist_ok: If ``False`` (the default), a :class:`~python:FileExistsError` is raised if the
108+ target directory already exists. If ``True``, :class:`~python:FileExistsError` exceptions
109+ will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path
110+ component is not an existing non-directory file.
111+ :type exist_ok: bool
101112 """
102113
103114 if not isinstance (directory , pathlib .Path ):
104115 directory = pathlib .Path (directory )
105116
106117 if not directory .exists ():
107- directory .mkdir ()
118+ directory .mkdir (mode , parents , exist_ok )
108119
109120
110121def parent_path (path ):
0 commit comments