存档时:Python的IOError异常解压与尝试使用zip文件模块的extractall方法来解压缩zip文件时,我有以下错误深目录结构
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\zipfile.py", line 964, in extractall
self.extract(zipinfo, path, pwd)
File "C:\Python27\lib\zipfile.py", line 952, in extract
return self._extract_member(member, path, pwd)
File "C:\Python27\lib\zipfile.py", line 996, in _extract_member
target = file(targetpath, "wb")
IOError: [Errno 2] No such file or directory: 'D:\\GITHUBDB\\C++\\FellowTraveler
_Open-Transactions\\FellowTraveler-Open-Transactions-846a939\\sample-data\\no_ba
skets\\client_data\\purse\\tBy5mL14qSQXCJK7Uz3WlTOKRP9M0JZksA3Eg7EnnQ1\\T1Q3wZWg
eTUoaUvn9m1lzIK5tn5wITlzxzrGNI8qtaV\\CvHGtfOOKzQKL5hFL7J4iF5yAodVKhS1rxPzME5R9XA'
这是因为对路径的Windows 260个字符限制发生。 做CD不是一个选项,大部分路径都来自档案本身。 我已经阅读过有关“\\?\”的前缀,但将其添加到extractall参数不起作用,它在os.mkdir内zipfile模块中失败。
解决zipfile.py与“\\?\”似乎是可能的,但一个丑陋的解决方案。
有什么想法吗?
在根'D:'解压缩它,或者不要使用完整路径,或尝试使用合理的目录名称。 –
我无法使用任何其他目录名称:)因为归档来自外部源。 提取到D:\将节省我13个符号...它不会帮助。 –
您可以继承'ZipFile'来覆盖['_extract_member'](http://hg.python.org/cpython/file/70274d53c1dd/Lib/zipfile.py#l965)。也许截断所有长目录名称为10个字符+为唯一性的原始名称的散列。 – eryksun