Skip to content

Instantly share code, notes, and snippets.

@kemadz
Last active August 29, 2015 13:56
Show Gist options
  • Save kemadz/9017007 to your computer and use it in GitHub Desktop.
Save kemadz/9017007 to your computer and use it in GitHub Desktop.
rename photo to yyyy-mm-dd_hh.mm.ss.jpg with exif info
import os, exifread
from time import strftime, strptime
for x in os.listdir('.'):
print x
tags = exifread.process_file(open(x), details=False)
try:
#t = tags['EXIF DateTimeOriginal'].values
t = tags['Image DateTime'].values
print t
t = strptime(t, '%Y:%m:%d %H:%M:%S')
print t
print strftime('%Y-%m-%d %H:%M:%S.jpg', t)
os.utime(x, (int(strftime('%s')), int(strftime('%s', t))))
os.rename(x, strftime('%Y-%m-%d %H:%M:%S.jpg', t))
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment