-
-
Save tonykwok/62985b7a80d3302e2825c5ec37bd9de2 to your computer and use it in GitHub Desktop.
Zip a directory and get hash (useful for checking if contents have changed)
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
# http://stackoverflow.com/questions/1855095/how-to-create-a-zip-archive-of-a-directory | |
import os | |
import zipfile | |
import hashlib | |
import time | |
def zipdir(path, ziph): | |
for root, dirs, files in os.walk(path): | |
if '.git' not in root: | |
for file in files: | |
ziph.write(os.path.join(root, file)) | |
t0 = time.time() | |
zipf = zipfile.ZipFile('pyrevitplustab.zip', 'w', zipfile.ZIP_DEFLATED) | |
zipdir('pyrevitplus.tab', zipf) | |
zipf.close() | |
file_hash = hashlib.md5(open('pyrevitplustab.zip', 'rb').read()).hexdigest() | |
t1 = time.time() | |
total = t1-t0 | |
print('Done in:' , total) | |
print('Hash:' , file_hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment