Compare filename to datetimeoriginal

Started by uya1250, August 17, 2020, 01:23:44 PM

Previous topic - Next topic

uya1250

Hello,

I have my photos saved with the following filename: IMG_YYYYMMDD_HHMMSS. How do I convert the filename to a value I can compare to datetimeoriginal? I will be comparing the values using this code that I found on the forums:

exiftool -filename -if "$filename ne $datetimeoriginal" temp

StarGeek

Don't convert the filename, convert the time stamp with the -d (dateFormat) option.
exiftool -filename -if "$filename ne $datetimeoriginal" -d "IMG_%Y%m%d_%H%M%S.jpg" temp
Though this is case sensitive, so JPG/IMG would not match jpg/img.

Alternatively, you could just compare the numbers
exiftool -filename -if "${filename;m/(\d{8}_\d{6})/;$_=$1} ne $DateTimeOriginal" -d "%Y%m%d%_H%M%S" temp
This version  just grabs the YYYYMMDD_HHMMSS part of the filename and compares it to the DateTimeOriginal which has been formatted the same way.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

uya1250

Thank you for the help StarGeek. I tried the first code with -d and it worked perfectly. Is there a way to have it read all extensions? Besides .jpg, I also have .mp4 and .mov files in the folder. All of my .mp4 videos have datetimeoriginal. Most of my .mov videos have it too. But for the files that don't, how would I compare filecreatedate to filename?

As for the second code, I couldn't get it to work. I tried typing it and then copy and pasting it from your response but it just prints out all of the file names. Also, would you mind explaining how the code processes filename to grab YYYYMMDD_HHMMSS?

Phil Harvey

The second command should strip away everything but 8 digits + underscore + 6 digits of the file name, then compare that to DateTimeOriginal.  You can change the -if to a -p to see the logic expression that ExifTool will be evaluating (well, sort of... the interpolated values won't be quoted, but you'll get the idea):

exiftool -p "${filename;m/(\d{8}_\d{6})/;$_=$1} ne $DateTimeOriginal" -d "%Y%m%d%_H%M%S" temp

Maybe this will help you to figure out what is wrong.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Oops, typo.  It should be %d_%H, not %d%_H.

It always bites me in the ass when I don't actually test out the commands I post.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

uya1250

I got it to work now. It's much more convenient to not have to enter the file extension as with the first code. Thanks again Phil and StarGeek.

One last question. I want to also compare filename to createdate, modifydate, filecreatedate, and filemodifydate. Is there a way to combine the 5 comparisons into one line of code? Can the -if statement compare more than one value or do I have to enter multiple -if statements? I'm just trying to ensure consistency between my time tags.

StarGeek

That will make it longer, but just duplicate the same condition and link them together with or/and.

-if "${filename;m/(\d{8}_\d{6})/;$_=$1} ne $DateTimeOriginal or ${filename;m/(\d{8}_\d{6})/;$_=$1} ne $CreateDate"
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

uya1250

I just tested it out and comparisons work with both and and or. Thanks again for all of your help StarGeek.

StarGeek

And/or will give different results depending upon the metadata.  Or will return true if any of the dates don't equal the filename.  And will only return true if all of the dates don't match.  So if you have a case where only one date doesn't match but the others do, AND won't return the filename but OR will.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).