[python-win32] zip of file using python

a h ah.kode at gmail.com
Thu Apr 8 09:52:00 CEST 2010


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")
for fname in archive_list:
    fname = "logs_21-01-2010\\"+fname
    print fname
    zout.write(fname)
zout.close()

# test if the file is a valid pkzip file
if zipfile.is_zipfile(zfilename):
    print "%s is a valid pkzip file" % zfilename
else:
    print "%s is not a valid pkzip file" % zfilename

thnks in advance
ah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100408/26f3ca2b/attachment.html>


More information about the python-win32 mailing list