我有一个运行在windows上的python脚本,它只是将一个目录的内容从一个位置复制到另一个位置,但却遇到了下面的错误,不确定为什么,我可以确认源文件是否存在,你知道这里会出什么问题吗?
File "C:\crmapps\apps\python275-64\lib\shutil.py", line 208, in copytree
raise Error, errors
shutil.Error: [('\\\\WPLBD04\\pkg\\builds\\promote\\2712\\2712_QCA1990ANFC_CNSS.HW_SP.2.0_win_pro\\sumatraservices\\inRexW\\TLM-2009-07-15\\docs\\doxygen\\html\\classtlm__utils_1_1instance__specific__extensions__per__accessor-members.html', '\\\\sun\\sscn_dev_integration\\promote_per_CL_artifacts\\TECH_PRO.CNSS.2.0\\20141013125710_1115240\\2712_QCA1990ANFC_CNSS.HW_SP.2.0_win_pro\\sumatraservices\\inRexW\\TLM-2009-07-15\\docs\\doxygen\\html\\classtlm__utils_1_1instance__specific__extensions__per__accessor-members.html', "[Errno 2] No such file or directory:发布于 2014-10-15 07:42:49
如前所述,您已经超出了win32路径大小限制。事实证明,限制在win32中,而不是实际的文件系统驱动程序。解决这个问题的诀窍是在路径前面加上r"\\?\",这样win32就可以传递路径,而不会弄乱它们。只有在使用包括驱动器号的绝对名称时,它才起作用。
def win32_fix_long_path(path):
return r'\\?\' + os.path.realpath(path)它可能不会在所有情况下都起作用,特别是当您尝试将名称传递给子进程时。
发布于 2014-10-15 06:30:19
就像卢卡斯·格拉夫说的。问题是您的目标路径似乎有266个字符,因此是exceeds the limit。
目标路径更长。因此,错误始终存在于目标中,因为您的源已经存在。假设您的源路径不是扩展长度路径。
source: \\WPLBD04\pkg\builds\promote\2712\
destination: \\sun\sscn_dev_integration\promote_per_CL_artifacts\TECH_PRO.CNSS.2.0\20141013125710_1115240\string = win32api.GetShortPathName(path)
的\\?\添加前缀
>>> open(r"C:\%s\%s" % ("a"*1, "a"*254),"w")
<open file '...', mode 'w' at 0x0000000001F120C0>
>>> open(r"C:\%s\%s" % ("a"*2, "a"*254),"w")
IOError: [Errno 2] No such file or directory: '...'
>>> open(r"C:\%s\%s" % ("a"*1, "a"*255),"w")
IOError: [Errno 2] No such file or directory: '...'
>>> open(r"\\?\C:\%s\%s" % ("a"*1, "a"*255),"w")
<open file '\\\\?\\...', mode 'w' at 0x0000000001F12150>夸张:我不认为扩展长度路径对文件访问速度有任何明显的副作用。如果只想避免长度过长的路径,请使用长度小于或等于源路径的目标路径。
https://stackoverflow.com/questions/26371317
复制相似问题