我有一个目录/ a / b / c有文件和子目录。 我需要复制/ x / y / z目录中的/ a / b / c / *。 我可以使用哪些python方法? 我尝试了shutil.copytree("a/b/c", "/x/y/z") ,但python试图创build/ x / y / z并引发一个error "Directory exists" 。
在Python中,在包含只读文件的文件夹上运行shutil.rmtree时,会显示以下exception: File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) File "C:\Python26\lib\shutil.py", line 216, in rmtree rmtree(fullname, ignore_errors, onerror) […]
从包含名为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' 我希望这样工作,就像我input的一样: $ mkdir foo $ cp bar/* foo/ $ cp […]