[python-win32] zip of file using python

Werner F. Bruhin werner.bruhin at free.fr
Thu Apr 8 11:26:50 CEST 2010


On 08/04/2010 09:52, a h wrote:
> hi
> I want to zip a folder using python script. I have written below piece
> of code, but i found that total size of all file is equal to the size of
> resultant zip file. so no compression is done. Its just put all the
> files in a folder and say save it with an extension(.zip). May be i am
> wrong someway, but i checked it correctly.
> import zipfile, os
> archive_list = os.listdir("logs_21-01-2010")
> # save the files in the archive_list into a PKZIP format .zip file
> zfilename = "logs_21-01-2010_.zip"
> zout = zipfile.ZipFile(zfilename, "w")
I guess/think you need to define compression, see the doc for:
12.4.1 ZipFile Objects

class ZipFile(file[, mode[, compression[, allowZip64]]])

e.g.
zipfile.ZipFile('afile.zip', "w", zipfile.ZIP_DEFLATED)

Werner



More information about the python-win32 mailing list