How to use zipfile

Thorsten Goertz thorsten at goertz.com
Wed Nov 6 07:58:36 EST 2002


I use it in this way:

import zipfile
archive = zipfile.ZipFile( "abc.zip", "w", zipfile.ZIP_DEFLATED )
source = "a.txt"
destination = source
archive.write( source, destination )
archive.close( )

I'd prefer to create a "virtual directory" in the root of the zipfile
(with destination = os.path.join( "abc", source ). Archives without
this virtual root directory sometimes caused trouble to me. I unzipped
an archive and contaminated the current directory with a lot of files
that I expected to be in a subdir that has been named like the
archive...


"Jack Lau" <jack98lau at hotmail.com> wrote in message news:<3dc8c6b3$1 at shknews01>...
> Hello,
> 
> I am a beginner to learn python. Could anyone tell me how to use zipfile. I
> want to zip a file like "a.txt" and zipped it into "abc.zip". Then how can I
> do ?
> 
> Thanks in advance!



More information about the Python-list mailing list