Skip to content

Instantly share code, notes, and snippets.

@austlane
Created July 15, 2016 14:45
Show Gist options
  • Save austlane/cb0d779ca3149a68f42549cf19f11f21 to your computer and use it in GitHub Desktop.
Save austlane/cb0d779ca3149a68f42549cf19f11f21 to your computer and use it in GitHub Desktop.
Generate an MD5 for every file in the directory (recursively)
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