Created
September 10, 2016 23:01
-
-
Save gtalarico/ca59946a627df548f4e506df2933c277 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 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