Recursively copy a directory tree and return the destination directory. If exception(s) occur, an Error is raised with a list of reasons. If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the c
(src, dst, symlinks=False, ignore=None, copy_function=copy2,
ignore_dangling_symlinks=False, dirs_exist_ok=False)
| 609 | return dst |
| 610 | |
| 611 | def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, |
| 612 | ignore_dangling_symlinks=False, dirs_exist_ok=False): |
| 613 | """Recursively copy a directory tree and return the destination directory. |
| 614 | |
| 615 | If exception(s) occur, an Error is raised with a list of reasons. |
| 616 | |
| 617 | If the optional symlinks flag is true, symbolic links in the |
| 618 | source tree result in symbolic links in the destination tree; if |
| 619 | it is false, the contents of the files pointed to by symbolic |
| 620 | links are copied. If the file pointed to by the symlink doesn't |
| 621 | exist, an exception will be added in the list of errors raised in |
| 622 | an Error exception at the end of the copy process. |
| 623 | |
| 624 | You can set the optional ignore_dangling_symlinks flag to true if you |
| 625 | want to silence this exception. Notice that this has no effect on |
| 626 | platforms that don't support os.symlink. |
| 627 | |
| 628 | The optional ignore argument is a callable. If given, it |
| 629 | is called with the `src` parameter, which is the directory |
| 630 | being visited by copytree(), and `names` which is the list of |
| 631 | `src` contents, as returned by os.listdir(): |
| 632 | |
| 633 | callable(src, names) -> ignored_names |
| 634 | |
| 635 | Since copytree() is called recursively, the callable will be |
| 636 | called once for each directory that is copied. It returns a |
| 637 | list of names relative to the `src` directory that should |
| 638 | not be copied. |
| 639 | |
| 640 | The optional copy_function argument is a callable that will be used |
| 641 | to copy each file. It will be called with the source path and the |
| 642 | destination path as arguments. By default, copy2() is used, but any |
| 643 | function that supports the same signature (like copy()) can be used. |
| 644 | |
| 645 | If dirs_exist_ok is false (the default) and `dst` already exists, a |
| 646 | `FileExistsError` is raised. If `dirs_exist_ok` is true, the copying |
| 647 | operation will continue if it encounters existing directories, and files |
| 648 | within the `dst` tree will be overwritten by corresponding files from the |
| 649 | `src` tree. |
| 650 | """ |
| 651 | sys.audit("shutil.copytree", src, dst) |
| 652 | with os.scandir(src) as itr: |
| 653 | entries = list(itr) |
| 654 | return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks, |
| 655 | ignore=ignore, copy_function=copy_function, |
| 656 | ignore_dangling_symlinks=ignore_dangling_symlinks, |
| 657 | dirs_exist_ok=dirs_exist_ok) |
| 658 | |
| 659 | if hasattr(os.stat_result, 'st_file_attributes'): |
| 660 | def _rmtree_islink(st): |