If you plan to do a lot of ZIP file creation from Python, it's usually a whole lot faster, and may produce smaller files, if you call out to an external utility to do the compression instead of doing it from within the Python zipfile module. You can also pass compression arguments like -9 that produce smaller files. A while back I wrote a wrapper around zipfile that can call out to the external program if available, otherwise it falls back on using internal zipfile. I can send that to you or post it here if it would help you.<br>
<br>regards,<br>-Preston<br><br><br><div class="gmail_quote">On Thu, Apr 8, 2010 at 4:53 AM, a h <span dir="ltr"><<a href="mailto:ah.kode@gmail.com">ah.kode@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>thanks... i tried compression as zipfile.ZIP_DEFLATED and it works fine. Now i used WinRar software to compress a 1.5GB file, it results into a 42MB file where as using my script it results into 62 MB file. Is it because of different format, if so, is there any winrar lib or equivalent lib for python.</div>
<div> </div><font color="#888888">
<div>ah<br><br></div></font><div><div></div><div class="h5">
<div class="gmail_quote">On Thu, Apr 8, 2010 at 2:56 PM, Werner F. Bruhin <span dir="ltr"><<a href="mailto:werner.bruhin@free.fr" target="_blank">werner.bruhin@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="padding-left: 1ex; margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204);">
<div>On 08/04/2010 09:52, a h wrote:<br>
<blockquote class="gmail_quote" style="padding-left: 1ex; margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204);">hi<br>I want to zip a folder using python script. I have written below piece<br>of code, but i found that total size of all file is equal to the size of<br>
resultant zip file. so no compression is done. Its just put all the<br>files in a folder and say save it with an extension(.zip). May be i am<br>wrong someway, but i checked it correctly.<br>import zipfile, os<br>archive_list = os.listdir("logs_21-01-2010")<br>
# save the files in the archive_list into a PKZIP format .zip file<br>zfilename = "logs_21-01-2010_.zip"<br>zout = zipfile.ZipFile(zfilename, "w")<br></blockquote></div>I guess/think you need to define compression, see the doc for:<br>
12.4.1 ZipFile Objects<br><br>class ZipFile(file[, mode[, compression[, allowZip64]]])<br><br>e.g.<br>zipfile.ZipFile('afile.zip', "w", zipfile.ZIP_DEFLATED)<br><br>Werner<br><br></blockquote></div></div>
</div></blockquote></div>