Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review feedback
  • Loading branch information
barneygale committed Aug 4, 2024
commit 4d6d2dcc777002dae1f81698a969619a5891edce
27 changes: 13 additions & 14 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1539,16 +1539,21 @@ Creating files and directories
Copying, renaming and deleting
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. method:: Path.copy(target, *, follow_symlinks=True, \
preserve_metadata=False, dirs_exist_ok=False, \
ignore=None, on_error=None)
.. method:: Path.copy(target, *, follow_symlinks=True, dirs_exist_ok=False, \
preserve_metadata=False, ignore=None, on_error=None)

Copy this file or directory tree to the given *target*. If both paths are
existing files, the target file will be replaced.
Copy this file or directory tree to the given *target*.

If a symlink is encountered and *follow_symlinks* is true (the default),
the symlink's target is copied. Otherwise, the symlink is recreated at the
destination.
If the source is a file, the target will be replaced if it is an existing
file. If the source is a symlink and *follow_symlinks* is true (the
default), the symlink's target is copied. Otherwise, the symlink is
recreated at the destination.

If the source is a directory and *dirs_exist_ok* is false (the default), a
:exc:`FileExistsError` is raised if the target is an existing directory.
If *dirs_exists_ok* is true, the copying operation will continue if it
encounters existing directories, and files within the destination tree will
Comment thread
barneygale marked this conversation as resolved.
Outdated
be overwritten by corresponding files from the source tree.

If *preserve_metadata* is false (the default), only directory structures
and file data are guaranteed to be copied. Set *preserve_metadata* to true
Expand All @@ -1557,12 +1562,6 @@ Copying, renaming and deleting
This argument has no effect when copying files on Windows (metadata is
always preserved in this case.)

If the source and target are existing directories and *dirs_exist_ok* is
false (the default), a :exc:`FileExistsError` is raised. Otherwise, the
copying operation will continue if it encounters existing directories, and
files within the destination tree will be overwritten by corresponding
files from the source tree.

If *ignore* is given, it should be a callable accepting one argument: a
source file or directory path. The callable may return true to suppress
copying of the path.
Expand Down
4 changes: 2 additions & 2 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ def _copy_data(self, target):
else:
raise

def copy(self, target, *, follow_symlinks=True, preserve_metadata=False,
dirs_exist_ok=False, ignore=None, on_error=None):
def copy(self, target, *, follow_symlinks=True, dirs_exist_ok=False,
preserve_metadata=False, ignore=None, on_error=None):
"""
Recursively copy this file or directory tree to the given destination.
"""
Expand Down