Create zip archive with multiple files
<p>I'm using following code where I pass .pdf file names with their paths to create zip file.</p>

<pre><code>for f in lstFileNames:
        with zipfile.ZipFile('reportDir' + str(uuid.uuid4()) + '.zip', 'w') as myzip:
            myzip.write(f)
</code></pre>

<p>It only archives one file though. <strong>I need to archive all files in my list in one single zip folder.</strong></p>

<p>Before people start to point out, yes I have consulted answers from <a href="http://stackoverflow.com/questions/12881294/django-create-a-zip-of-multiple-files-and-make-it-downloadable">this</a> and <a href="http://stackoverflow.com/questions/67454/serving-dynamically-generated-zip-archives-in-django">this</a> link but the code given there doesn't work for me. The code runs but I can't find generated zip file anywhere in my computer. </p>

<p>A simple straightforward answer would be appreciated. Thanks.</p>

<p>Order is incorrect. You are creating new zipfile object for each item in <code>lstFileNames</code></p>

<p>Should be like this.</p>

<pre><code>with zipfile.ZipFile('reportDir' + str(uuid.uuid4()) + '.zip', 'w') as myzip:
    for f in lstFileNames:   
        myzip.write(f)
</code></pre>

python