MCPcopy Index your code
hub / github.com/RustPython/RustPython / renames

Function renames

Lib/os.py:265–289  ·  view source on GitHub ↗

renames(old, new) Super-rename; create directories as necessary and delete any left empty. Works like rename, except creation of any intermediate directories needed to make the new pathname good is attempted first. After the rename, directories corresponding to rightmost path

(old, new)

Source from the content-addressed store, hash-verified

263 head, tail = path.split(head)
264
265def renames(old, new):
266 """renames(old, new)
267
268 Super-rename; create directories as necessary and delete any left
269 empty. Works like rename, except creation of any intermediate
270 directories needed to make the new pathname good is attempted
271 first. After the rename, directories corresponding to rightmost
272 path segments of the old name will be pruned until either the
273 whole path is consumed or a nonempty directory is found.
274
275 Note: this function can fail with the new directory structure made
276 if you lack permissions needed to unlink the leaf directory or
277 file.
278
279 """
280 head, tail = path.split(new)
281 if head and tail and not path.exists(head):
282 makedirs(head)
283 rename(old, new)
284 head, tail = path.split(old)
285 if head and tail:
286 try:
287 removedirs(head)
288 except OSError:
289 pass
290
291__all__.extend(["makedirs", "removedirs", "renames"])
292

Callers

nothing calls this directly

Calls 5

makedirsFunction · 0.85
renameFunction · 0.85
removedirsFunction · 0.85
splitMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected