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)
| 274 | head, tail = path.split(head) |
| 275 | |
| 276 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…