[英]How do I copy a folder and its contents (files/subdirectories) in Python with platform independent implementation
I need a function in python that lets me specify the source and destination paths for a folder and copies the source folder recursively into the destination folder. 我需要python中的一个函数,它允许我指定文件夹的源和目标路径,并将源文件夹递归地复制到目标文件夹中。 The implementation I am looking for needs to be platform independent 我正在寻找的实现需要独立于平台
You could use shutil.copytree : 你可以使用shutil.copytree :
shutil.copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2, ignore_dangling_symlinks=False) shutil.copytree(src,dst,symlinks = False,ignore = None,copy_function = copy2,ignore_dangling_symlinks = False)
Recursively copy an entire directory tree rooted at src, returning the destination directory. 递归复制以src为根的整个目录树,返回目标目录。 The destination directory, named by dst, must not already exist; 目标目录(由dst命名)必须不存在; it will be created as well as missing parent directories. 它将被创建以及缺少父目录。 Permissions and times of directories are copied with copystat(), individual files are copied using shutil.copy2(). 使用copystat()复制目录的权限和时间,使用shutil.copy2()复制单个文件。
import shutil
shutil.copytree(src, dst)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.