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

Function renames

tools/python-3.11.9-amd64/Lib/os.py:254–278  ·  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

(old, new)

Source from the content-addressed store, hash-verified

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

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