mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-73991: Add pathlib.Path.move()
(#122073)
Add a `Path.move()` method that moves a file or directory tree, and returns a new `Path` instance pointing to the target. This method is similar to `shutil.move()`, except that it doesn't accept a *copy_function* argument, and it doesn't check whether the destination is an existing directory.
This commit is contained in:
parent
aa905925e1
commit
625d0705b9
6 changed files with 225 additions and 4 deletions
|
@ -1536,8 +1536,8 @@ Creating files and directories
|
|||
available. In previous versions, :exc:`NotImplementedError` was raised.
|
||||
|
||||
|
||||
Copying, renaming and deleting
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Copying, moving and deleting
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. method:: Path.copy(target, *, follow_symlinks=True, dirs_exist_ok=False, \
|
||||
preserve_metadata=False, ignore=None, on_error=None)
|
||||
|
@ -1616,6 +1616,23 @@ Copying, renaming and deleting
|
|||
Added return value, return the new :class:`!Path` instance.
|
||||
|
||||
|
||||
.. method:: Path.move(target)
|
||||
|
||||
Move this file or directory tree to the given *target*, and return a new
|
||||
:class:`!Path` instance pointing to *target*.
|
||||
|
||||
If the *target* doesn't exist it will be created. If both this path and the
|
||||
*target* are existing files, then the target is overwritten. If both paths
|
||||
point to the same file or directory, or the *target* is a non-empty
|
||||
directory, then :exc:`OSError` is raised.
|
||||
|
||||
If both paths are on the same filesystem, the move is performed with
|
||||
:func:`os.replace`. Otherwise, this path is copied (preserving metadata and
|
||||
symlinks) and then deleted.
|
||||
|
||||
.. versionadded:: 3.14
|
||||
|
||||
|
||||
.. method:: Path.unlink(missing_ok=False)
|
||||
|
||||
Remove this file or symbolic link. If the path points to a directory,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue