0

I use the following command to bulk rename images from inside a bash script so each image is named according to the date the picture was taken:

exiftool -r -f '-filename<${CreateDate}_${model;tr/ /_/}_%f.jpg' -d %Y%m%d_T%H%M%S%%-c -ext jpg $targetDir

Sometimes, more often than I'd like, I encounter images that have incorrect values for dates in the metadata. For example:

$ exiftool -*date -G -s  *.jpg
[File]          FileModifyDate                  : 2014:12:22 18:32:03-07:00
[File]          FileAccessDate                  : 2014:12:23 11:41:23-07:00
[File]          FileInodeChangeDate             : 2014:12:23 11:40:00-07:00
[EXIF]          CreateDate                      : 2014/12/23 00:52:41

In this example, the FileModifyDate is the date I would have expected to be in the CreateDate tag, that is to say that the picture was taken 2014:12:22 18:32:03-07:00.

But because the CreateDate is not correct, the new file name is not correct. Well, from the perspective of the command used to rename the file it is correct (garbage in -> garbage out), but I would like the date used in the file name to be the date/time when the picture was actually taken.

In this example, is there some way to query the file for all date tags, and then select the earliest date available as the date to use in the renamed file name?

Also, using '${model;tr/ /_/}' I can replace any spaces that might be in the model tag with underscores. This is nice, but I would rather wrap this expression around the entire new file name. That way, since I'm using '%f.jpg', if the original file name contained any spaces, the resulting file name would not contain any spaces. Is this possible with exiftool?

  • I suspect you're more likely to get help here: superuser.com/questions/tagged/exiftool – MikeW Dec 23 '14 at 21:28
  • I also get the problem that the exif date is off by a constant amount on all files. You might figure out the offset and then derive the correct time for the whole set. After all, a camera won't put a random different time on every shot; it will have the clock set wrong. – JDługosz Dec 24 '14 at 1:32
  • Or maybe the timezone of the computer or camera is not set properly – Romeo Ninov Dec 24 '14 at 8:18
  • How do you move a question from one site to another without duplicating it? – axiopisty Dec 24 '14 at 15:41
1

You should be able to do some more crazy perl expressions inside those {}s. (I'd be more tempted to write something this complex in another language, actually, but for the sake of argument):

${CreateDate; use Date::Parse; @vals = strptime($_); sprintf("%-04d_%-02d_...", $vals[5], $vals[4]);}

Note: completely untested code. I doubt it works. But it gives you a direction to start, if you know perl.

  • +1, because, yeah, something like that. :) And also, a pointer to what may be a better approach: gexiv2 python bindings – mattdm Dec 24 '14 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.