Zipping and Unzipping files

Discussion in 'Python' started by Doug Tolton, Nov 21, 2003.

  1. Doug Tolton

    Doug Tolton Guest

    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")
     
    Doug Tolton, Nov 21, 2003
    #1
    1. Advertising

  2. Doug Tolton

    Peter Hansen Guest

    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
     
    Peter Hansen, Nov 21, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Lindstrom

    Unzipping Files

    Greg Lindstrom, Apr 1, 2005, in forum: Python
    Replies:
    1
    Views:
    353
    Larry Bates
    Apr 1, 2005
  2. OriginalBrownster

    Zipping Files to user defined Directory

    OriginalBrownster, Jul 28, 2006, in forum: Python
    Replies:
    4
    Views:
    346
    Danny Milosavljevic
    Sep 2, 2006
  3. OriginalBrownster

    Zipping files/zipfile module

    OriginalBrownster, Aug 2, 2006, in forum: Python
    Replies:
    5
    Views:
    481
    Brian Beck
    Aug 2, 2006
  4. OriginalBrownster
    Replies:
    4
    Views:
    356
    Dennis Lee Bieber
    Aug 21, 2006
  5. webcomm
    Replies:
    10
    Views:
    758
    John Machin
    Jan 10, 2009
Loading...

Share This Page