Skip to content

Instantly share code, notes, and snippets.

@tadone
Created November 2, 2017 13:57
Show Gist options
  • Save tadone/d06c50cede8d06a82c3da8b44cf69176 to your computer and use it in GitHub Desktop.
Save tadone/d06c50cede8d06a82c3da8b44cf69176 to your computer and use it in GitHub Desktop.
[Archive (Zip) directory] Zip a directory #python
#!/usr/bin/env python
import os
import zipfile
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment