ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: ericconn on April 13, 2023, 03:02:28 PM

Title: multiple/nest if statements
Post by: ericconn on April 13, 2023, 03:02:28 PM
What is the syntax for nesting -if statements? Say that I have two possible "good" Keyword/Title field combinations and I want to find all other "bad" Keyword/Title field combinations. Anything I write makes it essentially consider all Title fields as bad because I'm doubling my or, not doubling my if (if that makes sense  :-[ )

exiftool -if "$keywords =~ /Good/i and $Title !~ /Good1/" [or?] -if "$keywords =~ /Good/i and $Title !~ /Good2/" [...rest of code]
Title: Re: multiple/nest if statements
Post by: StarGeek on April 13, 2023, 04:36:50 PM
This would be where a little Perl knowledge can help. I believe and has a higher precedence than or, so the parentheses may not be necessary, though adding does help to make it more obvious.

exiftool -if "($keywords=~/Good/i and $Title!~/Good1/) or ($keywords=~/Good/i and $Title!~/Good2/)" [rest of code]

Title: Re: multiple/nest if statements
Post by: ericconn on April 17, 2023, 02:46:53 PM
Thanks. When I run this, it processes all the photos as having "bad" metadata because it runs one IF then another IF, not running both at the same time. I tried nesting the OR and it results in the same thing. I have a test folder with three test files; two with "good" metadata, one with "bad", and all files end up getting copied as being "bad".
Title: Re: multiple/nest if statements
Post by: Phil Harvey on April 17, 2023, 02:52:40 PM
If you were more specific about the exact value of the tags, the exact command  you used, and your expected result then I could help.

- Phil
Title: Re: multiple/nest if statements
Post by: ericconn on April 17, 2023, 03:53:40 PM
Apologies for being vague. Here is my code.

exiftool -if "($keywords =~ /Portrait/i and $Title !~ /Approved/) or ($keywords =~ /Member Portrait/i and $Title !~ /Sessions/)" -o "D:\All Portraits\Good Metadata" "D:\All Portraits"
Title: Re: multiple/nest if statements
Post by: StarGeek on April 17, 2023, 08:28:29 PM
We need the value of the tags as well.

Also, if Title does not exist in the file, that result will always be false.
Title: Re: multiple/nest if statements
Post by: ericconn on April 24, 2023, 03:44:43 PM
The values of the tags are in that code.

As far as a blank Title field, I have another line of code to deal with that.

To correct a small issue, here is the code:

exiftool -if "($keywords =~ /Portrait/i and $Title !~ /Approved/) or ($keywords =~ /Portrait/i and $Title !~ /Sessions/)" -o "D:\All Portraits\Good Metadata" "D:\All Portraits"