@@ -242,7 +242,7 @@ Directory and files operations
242242
243243.. function :: copytree(src, dst, symlinks=False, ignore=None, \
244244 copy_function=copy2, ignore_dangling_symlinks=False, \
245- dirs_exist_ok=False)
245+ dirs_exist_ok=False, * , copy_dir_stat=True )
246246
247247 Recursively copy an entire directory tree rooted at *src * to a directory
248248 named *dst * and return the destination directory. All intermediate
@@ -251,6 +251,12 @@ Directory and files operations
251251 Permissions and times of directories are copied with :func: `copystat `,
252252 individual files are copied using :func: `~shutil.copy2 `.
253253
254+ If *copy_dir_stat * is false, directory metadata is not copied with
255+ :func: `copystat `, e.g. to copy a read-only tree into a writable one.
256+ It defaults to true. Note that file metadata is always handled by
257+ *copy_function *: use e.g. ``copy_function=shutil.copyfile `` to skip
258+ that as well.
259+
254260 If *symlinks * is true, symbolic links in the source tree are represented as
255261 symbolic links in the new tree and the metadata of the original links will
256262 be copied as far as the platform allows; if false or omitted, the contents
@@ -306,6 +312,9 @@ Directory and files operations
306312 .. versionchanged :: 3.8
307313 Added the *dirs_exist_ok * parameter.
308314
315+ .. versionchanged :: 3.16
316+ Added the *copy_dir_stat * parameter.
317+
309318.. function :: rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None)
310319
311320 .. index :: single: directory; deleting
@@ -316,6 +325,12 @@ Directory and files operations
316325 handled by calling a handler specified by *onexc * or *onerror * or, if both
317326 are omitted, exceptions are propagated to the caller.
318327
328+ If *path * is a symbolic link to a directory followed by a trailing path
329+ separator, such as ``'link/' ``, the operating system resolves the link, so
330+ :func: `!rmtree ` deletes the contents of the directory it points to and then
331+ fails to remove *path * itself. :class: `pathlib.Path ` strips trailing
332+ separators, so ``rmtree(Path('link/')) `` refuses the link as usual.
333+
319334 This function can support :ref: `paths relative to directory descriptors
320335 <dir_fd>`.
321336
0 commit comments