-5

如何使用 Python 将文件夹 A 中的所有内容(包括文件夹)复制到现有文件夹 B?

4

1 回答 1

0

您可以使用 shutil 包https://docs.python.org/3/library/shutil.html#shutil.copytree中的 copytree 函数。

from shutil import copytree

src_path = "path/of/your/source/dir"
dest_path = "path/of/your/destination/dir"

copytree(src_path, dest_path, dirs_exist_ok=True)

dirs_exist_ok=True如果 dest_path 已经存在,并且您想要覆盖现有文件,则该参数很有用。

于 2020-11-27T16:39:43.553 回答