[英]ZipFile can't extract a zip with directories
我正在尝试用Python解压缩文件。 我正在使用以下功能:
def unzip(source_filename, dest_dir):
zf = zipfile.ZipFile(source_filename)
for member in zf.infolist():
# Path traversal defense copied from
# http://hg.python.org/cpython/file/tip/Lib/http/server.py#l789
words = filter(None, member.filename.split('/'))
path = dest_dir
for word in words[:-1]:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word)
zf.extract(member, path)
使用名为“ gui”的目录解压缩.zip时,出现以下错误:
Traceback (most recent call last):
File "MCManager.py", line 137, in add
unzip(addedFilepath, dirUnzipped)
File "MCManager.py", line 19, in unzip
zf.extract(member, path)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/zipfile.py", line 928, in extract
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/zipfile.py", line 962, in _extract_member
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/os.py", line 157, in makedirs
OSError: [Errno 20] Not a directory: '/Users/student/Library/Application Support/minecraft/temp/unzipped/gui/gui'
ZipFile()是否有问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.