我正在运行 python zipfile extractall,它解压缩到一个超过 255 个字符的路径。在 Windows 7 64 位上运行它。
我遇到以下错误 [Errno 2] No such file or directory: u'
有什么想法吗?
它是我要从中提取/提取到的网络文件夹。所以我将文件夹挂载为网络驱动器 t:\这暂时解决了问题。
最佳答案
这对我有用:
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
取自 pathname too long to open? 的 winapi_path
关于从长路径提取文件时 Windows 上的 Python Zipfile extractall IOError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40419395/