Trouble with Multiple -if Conditions

Started by pwade, September 07, 2023, 01:31:04 PM

Previous topic - Next topic

pwade

I'm intending to check the color mode on any TIF files modified after a certain date.  I'm on Windows, and this is the command I've been using to test:

exiftool -ext tif -if "$FileModifyDate ge '2023:09:01'" -execute -ext tif -if "$ColorMode eq 'RGB' " -CreateDate -ColorMode -filemodifydate \\Path to files

The first -if works correctly, meaning it only shows me files modified after 9/1/23 and outputs my three fields.  When I add the -execute and second -if it seems to complete ignore that and returns any file matching the second condition.

Also, if I don't also include the -ext tif on the second part it process all files, not just TIF.

What am I doing wrong?  I've seen several examples and I think I'm using the same syntax but I'm probably missing something silly.

pwade

I'm just dumb.  I was looking at the wrong examples.  I didn't realize I could do "and" in the -if.

StarGeek

Quote from: pwade on September 07, 2023, 01:31:04 PMWhen I add the -execute and second -if it seems to complete ignore that and returns any file matching the second condition.

Also, if I don't also include the -ext tif on the second part it process all files, not just TIF.

From the docs on the -execute option

QuoteExecute command for all arguments up to this point on the command line (plus any arguments specified by -common_args).

Everything before the -execute is a completely separate command than what follows after.  Nothing carries over.  The only things that will apply to both will be anything that follows the -Common_Args option.

Your command as written is the equivalent to running these two separate commands.  The first half should have simply failed with a No file specified error, as no paths or files were included in the first half.
exiftool -ext tif -if "$FileModifyDate ge '2023:09:01'"
exiftool -execute -ext tif -if "$ColorMode eq 'RGB' " -CreateDate -ColorMode -filemodifydate \\Path to files

It sounds like you have it figured out, but just as an example, a proper command using execute would have been this, assuming you were looking for the two items separately.  Notice that you do not need to have a second -execute at the end of the second half of the command. That's a mistake that took me some time to figure out.
exiftool -if "$FileModifyDate ge '2023:09:01'" -execute -if "$ColorMode eq 'RGB'" -Common_Args -ext tif -CreateDate -ColorMode -filemodifydate \\Path to files
* 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).