I think it would be nice to have a make_parents
arg for pathlib.Path.rename
and pathlib.Path.replace
.
def rename(self, target: pathlib.Path, make_parents: bool = False)
def replace(self, target: pathlib.Path, make_parents: bool = False)
Implementation should be pretty trivial, with a proof-of-concept like so:
if make_parents:
target.parent.mkdir(parents=True, exist_ok=True)
os.rename(self, target)
return self.__class__(target)
and similar for replace
.
In order to keep the API similar to mkdir
, we could use parents
instead of make_parents
.
This would diverge the API from os.replace
and os.rename
, though I’m not sure how critical that API unity is now that pathlib
is mature.