Extracting Zip Files

Martin Franklin mfranklin1 at mfranklin.is-a-geek.org
Tue Sep 28 17:21:47 EDT 2004


Greg Lindstrom wrote:
> I've been zipping up files for months with zipfile, but today I was asked to
> extract the contents of a zip file and was sure there would be an "extract"
> method...but there's not one that I can find!  Am I just missing something??
> I found a module, unzip.py, on Parnassus, but it doesn't work.  Does anyone
> have a way for me to extract files?  Thanks!
> 
> 
> Greg Lindstrom                                         (501) 975-4859
> NovaSys Health                  greg.lindstrom at novasyshealth.com
> 
> "We are the music makers, and we are the dreamers of dreams"  W.W.
> 

$ pydoc zipfile
<snip>
      |  namelist(self)
      |      Return a list of file names in the archive.
      |
      |  printdir(self)
      |      Print a table of contents for the zip file.
      |
      |  read(self, name)
      |      Return file bytes (as a string) for name.
      |
      |
<snip>

For example [untested]:-

zfile = zipfile.ZipFile("SomeZipFile.zip")

for name in zfile.namelist():
     localFile = open(name, "wb")
     localFile.write(zfile.read(name))
     localFile.close()


Cheers
Martin






















More information about the Python-list mailing list