Created
October 9, 2015 17:54
-
-
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
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
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