Created
July 15, 2016 14:45
-
-
Save austlane/cb0d779ca3149a68f42549cf19f11f21 to your computer and use it in GitHub Desktop.
Generate an MD5 for every file in the directory (recursively)
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
import os | |
import subprocess | |
ignored_extensions = ('.py', '.md5') | |
rootdir = os.getcwd() | |
for subdir, dirs, files in os.walk(os.getcwd()): | |
for filename in files: | |
os.chdir(subdir) | |
relative_path = os.path.normpath(os.path.relpath(os.getcwd(), rootdir)) | |
relative_filename = os.path.join(relative_path, filename) | |
if filename.startswith('_'): | |
print "IGNORE: %s" | |
elif os.path.isfile(filename+'.md5'): | |
print "EXISTS: %s.md5" % relative_filename | |
elif not filename.endswith(ignored_extensions): | |
with open(filename+'.md5',"wb") as md5: | |
subprocess.Popen(["md5sum", filename], stdout=md5) | |
print "CREATE: %s.md5" % relative_filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment