我正在运行Python zipfile extractall,它正在解压到一个超过255个字符的路径。在Windows 7 64位上运行此操作时,我遇到了以下错误:[Errno 2] No such file or directory: u'
有任何想法吗?
我想从/到网络文件夹中提取。因此,我将该文件夹挂载为网络驱动器T:\,这暂时解决了问题。
我正在运行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
winapi_path来源于路径名过长无法打开?
import os; os.getcwd()
命令,并确保它返回的路径是包含所需文件的目录。 - naiveai