Last active
August 29, 2015 14:12
-
-
Save jossef/4c728da18ec927aa2a0c to your computer and use it in GitHub Desktop.
python jpg files MD5 renamer
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
#!/bin/sh/ python | |
import os | |
import shutil | |
import hashlib | |
output_dir = '.' | |
for dirpath, dnames, fnames in os.walk("."): | |
for f in fnames: | |
full_path = os.path.join(dirpath, f) | |
if f.endswith(".jpg"): | |
md5_hash = hashlib.md5(open(full_path, 'rb').read()).hexdigest() | |
filename = '{0}.jpg'.format(md5_hash) | |
new_path = os.path.join(output_dir, filename) | |
if os.path.exists(new_path): | |
os.remove(new_path) | |
shutil.copy2(full_path, new_path) | |
print filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment