我正在运行python zipfile extractall,它提取到一个长度超过255个字符的路径。在Windows 7 64bit上运行此命令。
我要遵循错误[Errno 2] No such file or directory: u'
有什么想法吗?
我想从中提取的网络文件夹。所以我将文件夹挂载为网络驱动器t:\这暂时解决了这个问题。
答案 0 :(得分:2)
这对我有用:
class ZipfileLongPaths(zipfile.ZipFile):
def _extract_member(self, member, targetpath, pwd):
targetpath = winapi_path(targetpath)
return zipfile.ZipFile._extract_member(self, member, targetpath, pwd)
winapi_path是:
def winapi_path(dos_path, encoding=None):
path = os.path.abspath(dos_path)
if path.startswith("\\\\"):
path = "\\\\?\\UNC\\" + path[2:]
else:
path = "\\\\?\\" + path
return path
winapi_path取自pathname too long to open?