Questions tagged «shutil»

14
如何使用Python将文件的整个目录复制到现有目录中?
从包含一个名为目录bar(包含一个或多个文件)和一个目录baz(也包含一个或多个文件)的目录中运行以下代码。确保没有名为的目录foo。 import shutil shutil.copytree('bar', 'foo') shutil.copytree('baz', 'foo') 它将失败并显示: $ python copytree_test.py Traceback (most recent call last): File "copytree_test.py", line 5, in <module> shutil.copytree('baz', 'foo') File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/shutil.py", line 110, in copytree File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/os.py", line 172, in makedirs OSError: [Errno 17] File exists: 'foo' 我希望它的工作方式与输入相同: $ mkdir foo $ cp bar/* foo/ …
210 python  shutil  copytree 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.