@@ -1536,8 +1536,8 @@ Creating files and directories
15361536 available. In previous versions, :exc: `NotImplementedError ` was raised.
15371537
15381538
1539- Copying, renaming and deleting
1540- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1539+ Copying, moving and deleting
1540+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15411541
15421542.. method :: Path.copy(target, *, follow_symlinks=True, dirs_exist_ok=False, \
15431543 preserve_metadata=False, ignore=None, on_error=None)
@@ -1575,6 +1575,18 @@ Copying, renaming and deleting
15751575 .. versionadded :: 3.14
15761576
15771577
1578+ .. method :: Path.copy_into(target_dir, *, follow_symlinks=True, \
1579+ dirs_exist_ok=False, preserve_metadata=False, \
1580+ ignore=None, on_error=None)
1581+
1582+ Copy this file or directory tree into the given *target_dir *, which should
1583+ be an existing directory. Other arguments are handled identically to
1584+ :meth: `Path.copy `. Returns a new :class: `!Path ` instance pointing to the
1585+ copy.
1586+
1587+ .. versionadded :: 3.14
1588+
1589+
15781590.. method :: Path.rename(target)
15791591
15801592 Rename this file or directory to the given *target *, and return a new
@@ -1616,59 +1628,50 @@ Copying, renaming and deleting
16161628 Added return value, return the new :class: `!Path ` instance.
16171629
16181630
1619- .. method :: Path.unlink(missing_ok=False )
1631+ .. method :: Path.move(target )
16201632
1621- Remove this file or symbolic link. If the path points to a directory,
1622- use :func: ` Path.rmdir ` or :func: ` Path.delete ` instead .
1633+ Move this file or directory tree to the given * target *, and return a new
1634+ :class: ` ! Path` instance pointing to * target * .
16231635
1624- If *missing_ok * is false (the default), :exc: `FileNotFoundError ` is
1625- raised if the path does not exist.
1636+ If the *target * doesn't exist it will be created. If both this path and the
1637+ *target * are existing files, then the target is overwritten. If both paths
1638+ point to the same file or directory, or the *target * is a non-empty
1639+ directory, then :exc: `OSError ` is raised.
16261640
1627- If *missing_ok * is true, :exc: `FileNotFoundError ` exceptions will be
1628- ignored (same behavior as the POSIX ``rm -f `` command).
1641+ If both paths are on the same filesystem, the move is performed with
1642+ :func: `os.replace `. Otherwise, this path is copied (preserving metadata and
1643+ symlinks) and then deleted.
16291644
1630- .. versionchanged :: 3.8
1631- The *missing_ok * parameter was added.
1645+ .. versionadded :: 3.14
16321646
16331647
1634- .. method :: Path.rmdir( )
1648+ .. method :: Path.move_into(target_dir )
16351649
1636- Remove this directory. The directory must be empty; use
1637- :meth: `Path.delete ` to remove a non-empty directory.
1650+ Move this file or directory tree into the given *target_dir *, which should
1651+ be an existing directory. Returns a new :class: `!Path ` instance pointing to
1652+ the moved path.
16381653
1654+ .. versionadded :: 3.14
16391655
1640- .. method :: Path.delete(ignore_errors=False, on_error=None)
16411656
1642- Delete this file or directory. If this path refers to a non-empty
1643- directory, its files and sub-directories are deleted recursively.
1657+ .. method :: Path.unlink(missing_ok=False)
16441658
1645- If *ignore_errors * is true, errors resulting from failed deletions will be
1646- ignored. If *ignore_errors * is false or omitted, and a callable is given as
1647- the optional *on_error * argument, it will be called with one argument of
1648- type :exc: `OSError ` each time an exception is raised. The callable can
1649- handle the error to continue the deletion process or re-raise it to stop.
1650- Note that the filename is available as the :attr: `~OSError.filename `
1651- attribute of the exception object. If neither *ignore_errors * nor
1652- *on_error * are supplied, exceptions are propagated to the caller.
1659+ Remove this file or symbolic link. If the path points to a directory,
1660+ use :func: `Path.rmdir ` instead.
16531661
1654- .. note ::
1662+ If *missing_ok * is false (the default), :exc: `FileNotFoundError ` is
1663+ raised if the path does not exist.
16551664
1656- When deleting non-empty directories on platforms that lack the necessary
1657- file descriptor-based functions, the :meth: `~Path.delete ` implementation
1658- is susceptible to a symlink attack: given proper timing and
1659- circumstances, attackers can manipulate symlinks on the filesystem to
1660- delete files they would not be able to access otherwise. Applications
1661- can use the :data: `~Path.delete.avoids_symlink_attacks ` method attribute
1662- to determine whether the implementation is immune to this attack.
1665+ If *missing_ok * is true, :exc: `FileNotFoundError ` exceptions will be
1666+ ignored (same behavior as the POSIX ``rm -f `` command).
16631667
1664- .. attribute :: delete.avoids_symlink_attacks
1668+ .. versionchanged :: 3.8
1669+ The *missing_ok * parameter was added.
16651670
1666- Indicates whether the current platform and implementation provides a
1667- symlink attack resistant version of :meth: `~Path.delete `. Currently
1668- this is only true for platforms supporting fd-based directory access
1669- functions.
16701671
1671- .. versionadded :: 3.14
1672+ .. method :: Path.rmdir()
1673+
1674+ Remove this directory. The directory must be empty.
16721675
16731676
16741677Permissions and ownership
0 commit comments