Zipping and Unzipping files

D

Doug Tolton

Is there a simple way to zip and unzip files?

I'm looking for something along the lines of:

zfile = zipfile(r'c:\somefile.zip')
zfile.extract(r'c:\somefiles')

I've looked at the documentation for zlib and zipfile, and they seem
pretty comprehensive, but also extremely low level. If needed, I can
probably make a workable component from them, but I was wondering if
there is one already written that I'm just missing.
 
P

Peter Hansen

Doug said:
Is there a simple way to zip and unzip files?

I'm looking for something along the lines of:

zfile = zipfile(r'c:\somefile.zip')
zfile.extract(r'c:\somefiles')

I've looked at the documentation for zlib and zipfile, and they seem
pretty comprehensive, but also extremely low level. If needed, I can
probably make a workable component from them, but I was wondering if
there is one already written that I'm just missing.

Probably not, since it's likely to require slight differences in
each application. Try this (untested):

import os, zipfile
def extract(self, todir=''):
for name in self.namelist():
f = open(os.path.join(todir, name), 'wb')
f.write(self.read(name))
f.close()

zipfile.ZipFile.extract = extract

Now you should be able to execute the two example lines you showed above...

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top