从长路径提取文件时 Windows 上的 Python Zipfile extractall IOError

标签 python windows-7 python-zipfile

我正在运行 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/

相关文章:

python - 删除字符串中的字符 "' s "

Python分别从子进程stdout和stderr读取,同时保留顺序

python - 操作错误 : unable to open database file: sqlalchemy

android - 错误 1316 : while installing Mono for android on windows 7 (and visual studio 2010)

python - 名称错误 : "global name ' ZIP_STORED' is not defined"

python - 使用python ZipFile从zip中提取文件而不保留结构?

python - 使用第二列中的值从 pandas 列中删除特定数量的字母,Python

delphi - 如何让窗体像任务栏一样与屏幕边缘对齐?

python - Boost::Python Windows 7 64 位

python - Zipfile python模块字节大小差异