Created
November 2, 2017 13:57
-
-
Save tadone/d06c50cede8d06a82c3da8b44cf69176 to your computer and use it in GitHub Desktop.
[Archive (Zip) directory] Zip a directory #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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