def unzip(zippedFile, outPath):
"""Extract all files from a zip archive to a destination directory."""
newDir = False # the toplevel directory name in the zipfile
fh = open_file(zippedFile, 'rb')
with fh:
try:
z = zipfile.ZipFile(fh)
namelist = z.namelist()
newDir = namelist[0]
for name in namelist:
z.extract(name, outPath)
except RuntimeError as re:
msg("Error processing zip (RuntimeError): %s" % (re), True)
return False
except IOError as ioe:
msg("Error opening [%s]: %s" % (zippedFile, ioe.strerror), True)
return False
except zipfile.BadZipfile as bzf:
msg("Bad zip file: %s" % zippedFile, True)
return False
return newDir
评论列表
文章目录