Skip to content

Instantly share code, notes, and snippets.

@vidplace7
Created October 9, 2015 17:54
Show Gist options
  • Save vidplace7/28a5b27792877244ef04 to your computer and use it in GitHub Desktop.
Save vidplace7/28a5b27792877244ef04 to your computer and use it in GitHub Desktop.
Python/Linux: Create .md5 files for every file in a directory and it's subdirectories
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 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