MCPcopy Index your code
hub / github.com/python/cpython / renames

Function renames

Lib/os.py:276–300  ·  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

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

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…