Skip to content

Instantly share code, notes, and snippets.

@AmbivalentApe
Last active August 29, 2015 14:27
Show Gist options
  • Save AmbivalentApe/ec7c8c2ee30eff48010a to your computer and use it in GitHub Desktop.
Save AmbivalentApe/ec7c8c2ee30eff48010a to your computer and use it in GitHub Desktop.
For Marie
import exifread
import os
import sys
import re
dir_name = sys.argv[1]
print dir_name
regex = re.compile('[0-9]{8}\_[0-9]{6}\.')
DATE_TAG ='EXIF DateTimeOriginal'
EXTENSIONS=['jpg','jpeg']
for (base_folder,sub_folders,file_names) in os.walk(dir_name):
for file_name in file_names:
extension = file_name.split('.')[1]
groups =regex.match(file_name)
if extension.lower() not in EXTENSIONS or groups:
if not groups:
print 'Skipping %s' % (file_name)
continue
full_name = os.path.join(base_folder,'',file_name)
fh = open(full_name,'rb')
tags = exifread.process_file(fh)
if DATE_TAG in tags:
reformatted_timestamp = tags[DATE_TAG].values.replace(':','').replace(' ','_')
print '%s -> %s (%s)' % (file_name,reformatted_timestamp,extension)
os.rename(full_name,os.path.join(base_folder,reformatted_timestamp+'.'+extension))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment