Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Zipping and Unzipping files (http://www.velocityreviews.com/forums/t325176-zipping-and-unzipping-files.html)

Doug Tolton 11-21-2003 08:58 PM

Zipping and Unzipping files
 
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.


--
Doug Tolton
(format t "~a@~a~a.~a" "dtolton" "ya" "hoo" "com")


Peter Hansen 11-21-2003 09:10 PM

Re: Zipping and Unzipping files
 
Doug Tolton wrote:
>
> 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


All times are GMT. The time now is 01:44 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.