ExifTool Forum

ExifTool => Newbies => Topic started by: minime on November 23, 2021, 04:40:47 PM

Title: [SOLVED] Struggle how to get an IF statement integrated
Post by: minime on November 23, 2021, 04:40:47 PM
Hi all,

I am almost there, but I struggle with my "IF" part. So far I have this:

exiftool -r "-datetimeoriginal<filename" -P -overwrite_original C:/Images/

but I would like to only let it run IF:

1) datetimeoriginal is null
2) datetimeoriginal =! filename (without extension, in the format of "20071006_153426.jpg")

Should be simple, but would appreciate if someone could enlighten me on this one.

Many thanks!
Title: Re: Struggle how to get an IF statement integrated
Post by: StarGeek on November 23, 2021, 05:55:00 PM
Try this.  You need at least ver 12.22 in order to use Basename or have taken it from the example.config file (https://raw.githubusercontent.com/exiftool/exiftool/master/config_files/example.config).
exiftool -P -overwrite_original -if "not $DateTimeOriginal or ${DateTimeOriginal;DateFmt('%Y%m%d_%H%M%S')} ne $BaseName" "-datetimeoriginal<filename" /path/to/files/

The DateFmt helper function (https://exiftool.org//exiftool_pod.html#Helper-functions) formats the DateTimeOriginal to be the same as the BaseName of the file and then compares the two.
Title: Re: Struggle how to get an IF statement integrated
Post by: minime on November 23, 2021, 06:19:27 PM
Thank you kindly, that worked!

Is there a way to write what it did to a text file? I would have expected an update to 15 files, but it updated 17 and I would like to investigate what it really did.
Title: Re: Struggle how to get an IF statement integrated
Post by: StarGeek on November 23, 2021, 07:13:05 PM
To see everything that exiftool is doing, you could add the -v (-verbose) option (https://exiftool.org/exiftool_pod.html#v-NUM--verbose) and redirect the output to a txt file.  Using -v2 or -v3 will give you a lot of details.
Title: Re: Struggle how to get an IF statement integrated
Post by: minime on November 24, 2021, 02:31:27 AM
Thank you very much!!