Monday, November 5, 2012

Batch renaming photos using exiftool

I have a bunch of photos with random names in a folder. I would like to batch rename them to a "year month day hour minute second" format. Inside the directory:
exiftool '-filename<DateTimeOriginal' -d %y%m%d_%H%M%S%%-c.%%le *jpg
The DateTimeOriginal tag comes from the exif data. The -d option is for the date format. In particular here we put the %%-c in the end of the date so increasing numbers are added in the end of the file name of photos taken at the very same time. ".%%le" stands for "dot and lower case extension".

If the camera time was reset back then and we somehow find out that there is an offset of  5 years, 1 month, 30 days, 10 hours, 50 minutes and 3 seconds, then this will fix that:
exiftool "-DateTimeOriginal+=5:1:30 10:50:3" directory
where directory is the directory were the photos are stored.

Then one possibly needs to update the other exif date tags, like modification and creation dates. For that one has to use AllDates:
exiftool "-AllDates<DateTimeOriginal" directory
UPDATE: Actually correcting the dates may be much easier..
exiftool -alldates+=7 *.jpg
The line above will add 7 hours to all the date tags of all jpg images in the folder.