Thursday 2 January 2020

metadata - Rename a file based on whichever tag contains the earliest or oldest date?


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?




No comments:

Post a Comment

Why is the front element of a telephoto lens larger than a wide angle lens?

A wide angle lens has a wide angle of view, therefore it would make sense that the front of the lens would also be wide. A telephoto lens ha...