Skip to content

Instantly share code, notes, and snippets.

@jossef
Last active August 29, 2015 14:12
Show Gist options
  • Save jossef/4c728da18ec927aa2a0c to your computer and use it in GitHub Desktop.
Save jossef/4c728da18ec927aa2a0c to your computer and use it in GitHub Desktop.
python jpg files MD5 renamer
#!/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