multiple/nest if statements

Started by ericconn, April 13, 2023, 03:02:28 PM

Previous topic - Next topic

ericconn

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]

StarGeek

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]

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

ericconn

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".

Phil Harvey

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
...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 ($).

ericconn

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"

StarGeek

We need the value of the tags as well.

Also, if Title does not exist in the file, that result will always be false.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

ericconn

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"