I have a zip file which contains the following directory structure:
dir1\\dir2\\dir3a
dir1\\dir2\\dir3b
I\'m trying to unzip it and maintai
There's a very easy way if you're using Python 2.6: the extractall method.
However, since the zipfile
module is implemented completely in Python without any C extensions, you can probably copy it out of a 2.6 installation and use it with an older version of Python; you may find this easier than having to reimplement the functionality yourself. However, the function itself is quite short:
def extractall(self, path=None, members=None, pwd=None):
"""Extract all members from the archive to the current working
directory. `path' specifies a different directory to extract to.
`members' is optional and must be a subset of the list returned
by namelist().
"""
if members is None:
members = self.namelist()
for zipinfo in members:
self.extract(zipinfo, path, pwd)