title: Create .zip in Python?
body: <p>I'm trying to create a function in my script that zips the contents of a given source directory (<code>src</code>) to a zip file (<code>dst</code>). For example, <code>zip('/path/to/dir', '/path/to/file.zip')</code>, where <code>/path/to/dir</code> is a directory, and <code>/path/to/file.zip</code> doesn't exist yet. I <strong>do not</strong> want to zip the directory itself, this makes all the difference in my case. I want to zip the files (and subdirs) in the directory. This is what I'm trying:</p>
  
  <pre><code>def zip(src, dst):
      zf = zipfile.ZipFile("%s.zip" % (dst), "w")
      for dirname, subdirs, files in os.walk(src):
          zf.write(dirname)
          for filename in files:
              zf.write(os.path.join(dirname, filename))
      zf.close()
  </code></pre>
  
  <p>This creates a zip that is essentially <code>/</code>. For example, if I zipped <code>/path/to/dir</code>, extracting the zip creates a directory with "path" in it, with "to" in that directory, etc.</p>
  
  <p>Does anyone have a function that doesn't cause this problem?</p>
  
  <p>I can't stress this enough, it <strong>needs</strong> to zip the files in the directory, not the directoy itself.</p>