MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / makedirs

Function makedirs

tools/python-3.11.9-amd64/Lib/os.py:200–230  ·  view source on GitHub ↗

makedirs(name [, mode=0o777][, 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 directory already exists, ra

(name, mode=0o777, exist_ok=False)

Source from the content-addressed store, hash-verified

198# (Inspired by Eric Raymond; the doc strings are mostly his)
199
200def makedirs(name, mode=0o777, exist_ok=False):
201 """makedirs(name [, mode=0o777][, exist_ok=False])
202
203 Super-mkdir; create a leaf directory and all intermediate ones. Works like
204 mkdir, except that any intermediate path segment (not just the rightmost)
205 will be created if it does not exist. If the target directory already
206 exists, raise an OSError if exist_ok is False. Otherwise no exception is
207 raised. This is recursive.
208
209 """
210 head, tail = path.split(name)
211 if not tail:
212 head, tail = path.split(head)
213 if head and tail and not path.exists(head):
214 try:
215 makedirs(head, exist_ok=exist_ok)
216 except FileExistsError:
217 # Defeats race condition when another thread created the path
218 pass
219 cdir = curdir
220 if isinstance(tail, bytes):
221 cdir = bytes(curdir, 'ASCII')
222 if tail == cdir: # xxx/newdir/. exists if xxx/newdir exists
223 return
224 try:
225 mkdir(name, mode)
226 except OSError:
227 # Cannot rely on checking for EEXIST, since the operating system
228 # could give priority to other errors like EACCES or EROFS
229 if not exist_ok or not path.isdir(name):
230 raise
231
232def removedirs(name):
233 """removedirs(name)

Callers 1

renamesFunction · 0.85

Calls 3

splitMethod · 0.45
existsMethod · 0.45
isdirMethod · 0.45

Tested by

no test coverage detected