How can I compare EXIF Date to date encoded into file name?

Started 7 months ago | Discussions thread
OP TacticDesigns Veteran Member • Posts: 8,395
#5 working !!! -- Thank you!!!

Greybeard2017 wrote:

TacticDesigns wrote:

exiftool.exe -ext jpg -Filename -DateTimeOriginal -if "$Filename eq $DateTimeOriginal" -d "%Y-%m-%d-%Hh%Mm%SDSCF0033.JPG" subfolder -r

Does anyone know this last piece of information on how to truncate the $Filename for the -if comparison? So only take the 1st 19 characters of $Filename and not consider the rest?






Thank you so much!

That is so awesome!!!

NOTE: You've helped me before. I put the link in my signature so I'd be able to find it later. But I had totally forgotten I had gone down a similar path a couple years back. So . . . Thank you Again!!! Link So. Actually. If I want to implement #6, I think the Regex statement that you gave me 2 years ago would be the missing piece I would need for that task! I'm going to see how much I've messed up before deciding to try #6.

exiftool.exe -ext jpg -Filename -DateTimeOriginal -if "${filename;$_=substr($_,0,19);} eq $DateTimeOriginal" -d "%Y-%m-%d-%Hh%Mm%S" subfolder -r

I tried it and it works!!!

Now, in the final version, I'm going to replace "eq" with "ne" so that it only lists the files that the DATE+TIME in the filename "does not match (NotEqual)" the DateTimeOriginal tag inside the EXIF of the JPG file.

So . . .

exiftool.exe -ext jpg -Filename -DateTimeOriginal -if "${filename;$_=substr($_,0,19);} ne $DateTimeOriginal" -d "%Y-%m-%d-%Hh%Mm%S" subfolder -r > result.txt

I tried this "ne" version on a test copy of my 2000, 2002 and 2003 pictures. I totally screwed up my 2000 pictures. (I manually changed the DATE+TIME inside the filename to match another timestamp from the file. But that is easy enough to fix. But my 2002 files, only 4 files did not match. 3 were output files from Adobe Photoshop, where I am sure I didn't worry about preserving the original timestamp. But the 4th file, I don't know why it did not match. But because of this script, I know the exact location and filename so I can go take a closer look at this one. (As for the PSD files, I will figure out a way to inject a timestamp into them.) And my 2003 files, only 8 files did not match. And all of them are processed files from Adobe Photoshop. Things like group shots where I tweaked them. And a few panorama shots in there as well. So all good and expected!

So, thank you everyone that replied to this thread! I greatly appreciate all the input!!!

This means I am ready to test the integrity of my collection of pictures of friends and family and my kids growing up!!! Shortly I am going to have years 2000-2020 organized, cleaned up and pruned of bad shots, and shots that are too similar to others, or don't help tell the story. So basically trying to make it easier for my family and friends to find the shot they want. And to make it easier to keep backed-up!

I do have some pictures given to me from friends from about 1995-1999. A friend scanned in a bunch of film pictures. But no timestamp. So I was going to figure out how to inject a timestamp into those as our friend that scanned them happened to know the DATE that they happened and made folders with the appropriate DATE!!!

Thank you!!!

Take care & Happy Shooting!


For anyone that is interested, and/or might use this for themselves . . .

exiftool.exe -ext jpg -Filename -DateTimeOriginal -if "${filename;$_=substr($_,0,19);} ne $DateTimeOriginal" -d "%Y-%m-%d-%Hh%Mm%S" subfolder -r > result.txt

This is meant to take a JPG file, with a filename in the format . . .


<year>-<month>-<date>-<hours>h<minutes>m<seconds><original file name>.JPG

And see if the DATE+TIME that has been encoded into the filename (with the application NAMEXIF.EXE. I also modified my copy of Adobe Lightroom to match this filenaming scheme so everything would be the same.) matches the internal EXIF timestamp of when the picture was taken -- -DateTimeOriginal.

-ext jpg -> means to process only the files that have an "ext"ension of "jpg". NOTE: I am going to test this with avi to see if it can check the movie files I have in my collection as well.

-Filename -> return the -Filename tag value in the output for files that match the "-if" statement.

-DateTimeOriginal -> return the -DateTimeOriginal tag value in the output for the files that match the "-if" statement.

-if -> Process this conditional statement. Only the files that match this condition are then returned to the output stream.

"${filename;$_=substr($_,0,19);} ne $DateTimeOriginal" -> Everything inside the quotes is the condition. The 1st part takes the filename and then takes only the 1st 19 characters and throws away the rest. So 2008-12-07-09h27m54DSCF0033.JPG becomes 2008-12-07-09h27m54 in the comparison. And the $DateTimeOriginal, which takes the EXIF time stamp of when the picture was originally taken. The "ne" means Not-Equal. So only return a result if the two do not match. So basically if something is wrong.

-d "%Y-%m-%d-%Hh%Mm%S" -> Actually modifies the format of $DateTimeOriginal used for the conditional to reformat it to match the format of the DATE+TIME that is encoded into the filename. (That is a pretty cool trick, that I took from a forum post on exiftool. Link.)

subfolder -> is the name of a subfolder on my harddrive. So basically telling the script to start processing on this subfolder.

-r -> Do this recursively. So for all the subfolders as well.

> result.txt -> means to take the output that would normally go to the screen, and dump it into a file called result.txt. I'm just doing this so that I can take my time to look at the list so I can go and look at all the jpg files with an issue.


Ok. So a long time ago, I decided to rename my .jpg files with the app (NAMEXIF) so that . . . 1) The DATE+TIME can be seen in the filename. This, I was thinking, would make it easier for my wife and kids to know the DATE+TIME the picture was taken, without having to run it through an EXIF viewer. 2) Another side benefit was that when shooting with multiple cameras on vacation . . . when I tossed all the pictures from the different cameras into a single folder to view . . . the DATE+TIME stamp encoded into the beginning of the filename then put all the .jpg files into chronological order!!! A big benefit. 3) If I were shooting with two same "make" cameras that used the same file naming scheme . . . there was always the possibility of a filename collision, in which one picture would overwrite another picture if I decided to put them both into the same folder. By putting the DATE+TIME at the beginning of the filename (and keeping the old filename at the end), this greatly reduced the chance of a filename collision, since both cameras would need to take the picture at the same time (up to the second), and also happen to be on the same sequential number internally. 4) If I ever edited the picture and lost the internal timestamp . . . I would still have the DATE+TIME encoded into the filename as a reference to what that timestamp should have been.

-- hide signature --
 TacticDesigns's gear list:TacticDesigns's gear list
Fujifilm XP80 Nikon D5100 Pentax Q Nikon D750 Pentax *ist DS +9 more
Post (hide subjects) Posted by
Keyboard shortcuts:
FForum PPrevious NNext WNext unread UUpvote SSubscribe RReply QQuote BBookmark MMy threads
Color scheme? Blue / Yellow