python - How to create a zip archive of a directory -


How do I create a zip archive of a directory structure in Python?

As others have said, you should use. The documentation tells you which tasks are available, but in reality it is not understood how you can zip a complete directory. I think it's easy to explain with some example code:

  #! / Usr / bin / env python import os import zipfile def zipdir (path, zip): zipfile handle for # ziph root, file in OS valkel (path) for files in: ZIP, files: ziph.write (os. Path.join (root, file)) if __name__ == '__main__': zipf = zipfile.zipfile ('Python.zip', 'w', zipfile.ZIP_DEFLATED) zipdir ('tmp /', zipf) zipf.close ( )  

Optimized from:


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -