ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Birdman on February 24, 2024, 07:10:49 AM

Title: Two IF in one command possible?
Post by: Birdman on February 24, 2024, 07:10:49 AM
Hi there,

I would like to get the following two commands in one command:
exiftool -q -if "${Location} eq ${City}" "-Comment<${Location}, ${CountryCode}" -overwrite_original *.jpg
exiftool -q -if "${Location} ne ${City}" "-Comment<${Location}, ${City}, ${CountryCode}" -overwrite_original *.jpg
Is that possible (working under Windows)? I tried several ways, but none worked for both commands.

Regards,
Martin
Title: Re: Two IF in one command possible?
Post by: StarGeek on February 24, 2024, 11:49:22 AM
Not as a simple command, as these two -if conditions are opposite and write different values. You would need an if ... then ... else programming structure.

Technically, you could use Perl's ternary operator (https://perlmaven.com/the-ternary-operator-in-perl) ( Condition ? True value : False value) and self->GetValue('TAG') (https://exiftool.org/ExifTool.html#GetValue), but that is really messy IMO, and would be hard to troubleshoot if something went wrong.  Something like this (Edit: I have not tested this)
exiftool "-Comment<${Location;$_=($_ eq self->GetValue('City')) ? $_ . ',' . self->GetValue('CountryCode') : $_ . ',' . self->GetValue('City') . ',' . self->GetValue('CountryCode')}" file.jpg

Personally, I would just use two commands, as it's easier to figure out what you're trying to do if you have to fix or change it.
Title: Re: Two IF in one command possible?
Post by: Birdman on February 24, 2024, 12:01:37 PM
Quote from: StarGeek on February 24, 2024, 11:49:22 AM... Personally, I would just use two commands, as it's easier to figure out what you're trying to do if you have to fix or change it.
Thank you! I agree, that this seems to be the better way to go.