Newbie requires help me on how to use the ZipFile module please.

Ian Cook ian at kirbyfooty.com
Wed Nov 24 19:01:21 EST 2004


Hi,
Can someone PLEASE shed some light on using the ZipFile module
correctly.
I'm new to python so please excuse me if this is a 'dumb' question.

If I use mode='a' then what happens is the zip file just gets bigger
and bigger as the SAME file is appended to the zipfile.

If I use mode='w' then what happens is the zip file is erased before
adding files to it. Therefore I lose the files that were in the
original file zipfile.

What I want is to use the ZipFile module to UPDATE an existing zip
file, rather than append, or create a new zip file. The zip file then
contains my original files and any updated files.

Does anyone know how this can be done with the Zipfile module?

This is a snippet of the code I have now..

                try:
                    zf = zipfile.ZipFile(zfname,mode='a')
                except:
                    zf = zipfile.ZipFile(zfname,mode='w')
                    
                for name in cutflist:
                    fp = os.path.join(root,name)
                    print "adding ",fp,"...",
                    compresstype = zipfile.ZIP_DEFLATED
                    if zipfile.is_zipfile(fp):
                        compresstype = zipfile.ZIP_STORED
                    zf.write(fp,compress_type=compresstype)
                    print 'done.'



Thanks in advance.

Ian Cook
(Freeware author of Kirby Alarm And Task Scheduler)
http://www.kirbyfooty.com/



More information about the Python-list mailing list