diff options
Diffstat (limited to 'Lib/pathlib/_abc.py')
-rw-r--r-- | Lib/pathlib/_abc.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index 9943ea4..93758b1 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -14,7 +14,7 @@ resemble pathlib's PurePath and Path respectively. import functools import operator import posixpath -from errno import EINVAL +from errno import EINVAL, EXDEV from glob import _GlobberBase, _no_recurse_symlinks from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO from pathlib._os import copyfileobj @@ -928,6 +928,25 @@ class PathBase(PurePathBase): """ raise UnsupportedOperation(self._unsupported_msg('replace()')) + def move(self, target): + """ + Recursively move this file or directory tree to the given destination. + """ + self._ensure_different_file(target) + try: + return self.replace(target) + except UnsupportedOperation: + pass + except TypeError: + if not isinstance(target, PathBase): + raise + except OSError as err: + if err.errno != EXDEV: + raise + target = self.copy(target, follow_symlinks=False, preserve_metadata=True) + self.delete() + return target + def chmod(self, mode, *, follow_symlinks=True): """ Change the permissions of the path, like os.chmod(). |