我正在尝试使用以下代码复制源代码树并遇到错误,我不确定为什么会出现此错误?错误说 \\Ref\builds/out 存在但它不存在,“out”是目录脚本试图复制到目标的源位置,如果shutil不适合这种类型的复制,还有其他方法可以复制吗?
//local/mnt/workspace/04.01_HY11/out
\\Ref\builds/out
copying
Traceback (most recent call last):
File "test.py", line 21, in <module>
main()
File "test.py", line 18, in main
copytree(src,dst)
File "test.py", line 11, in copytree
shutil.copytree(s, d)
File "/pkg/qct/software/python/2.5.2/.amd64_linux26/lib/python2.5/shutil.py", line 110, in copytree
os.makedirs(dst)
File "/pkg/qct/software/python/2.5.2/.amd64_linux26/lib/python2.5/os.py", line 171, in makedirs
mkdir(name, mode)
OSError: [Errno 17] File exists: '\\\\Ref\\builds/out'
Python代码
import os,shutil
def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
s = os.path.join(src, item)
print s
d = os.path.join(dst, item)
print d
if os.path.isdir(s):
print "copying"
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
def main ():
src="//local/mnt/workspace/04.01_HY11"
dst="\\\\Ref\\builds"
copytree(src,dst)
if __name__ == '__main__':
main()