if or condition - BUG or what I'm doing wrong?

Started by RobiWan, May 30, 2024, 05:58:05 PM

Previous topic - Next topic

RobiWan

Hi,

I have 3 variants

1.exiftool -ProcessVersion "C:\DSLR\DSLR-RAW\ExtHDD 2501\A700\2011\05\07\_dsc3085.xmp"
Process Version                 : 11.0

2.exiftool -ProcessVersion "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2013\05\15\_z2a4218.xmp"
Process Version                 : 15.4

3. ProcessVersion does not exists in XMP file

What I want - I try to do something if -ProcessVersion=11.0 or -ProcessVersion does not exists

This works
(processVersion not exists)
exiftool -ProcessVersion -if "(!$ProcessVersion)" "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2014\07\31\_mg_0690.xmp"
(processVersion is 11.0)
exiftool -ProcessVersion -if "$ProcessVersion eq '11.0'" "C:\DSLR\DSLR-RAW\ExtHDD 2501\A700\2011\05\07\_dsc3085.xmp"
(processVersion is 15.4)
exiftool -ProcessVersion -if "$ProcessVersion eq '15.4'" "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2013\05\15\_z2a4218.xmp"
Process Version                 : 15.4

(processversion is 11.0 OR 15.4)
exiftool -ProcessVersion -if "($ProcessVersion eq '11.0') || ($ProcessVersion eq '15.4')" "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2013\05\15\_z2a4218.xmp"
Process Version                 : 15.4
exiftool -ProcessVersion -if "($ProcessVersion eq '11.0') || ($ProcessVersion eq '15.4')" "C:\DSLR\DSLR-RAW\ExtHDD 2501\A700\2011\05\07\_dsc3085.xmp"
Process Version                 : 11.0


BUT this will not work
(processVersion is 11.0 or not exists)
exiftool -ProcessVersion -if "($ProcessVersion eq '11.0') || (!$ProcessVersion)" "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2014\07\31\_mg_0690.xmp"
Why?

RobiWan

Hmm, interesting

this works

exiftool -ProcessVersion -if "(!$ProcessVersion) || ($ProcessVersion eq '11.0')" "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2014\07\31\_mg_0690.xmp"
The check as to whether a tag is set must therefore be the first

StarGeek

Quote from: RobiWan on May 30, 2024, 05:58:05 PMBUT this will not work
(processVersion is 11.0 or not exists)
exiftool -ProcessVersion -if "($ProcessVersion eq '11.0') || (!$ProcessVersion)" "C:\DSLR\DSLR-RAW\ExtHDD 2503\EOS5DMKIII\2014\07\31\_mg_0690.xmp"

I assume you mean this doesn't work when ProcessVersion doesn't exist in the file.

When ProcessVersion doesn't exist, then the whole if statement will fail at "($ProcessVersion eq '11.0')". You have to include a test to see if it exists

C:\>exiftool -G1 -a -s -filename -ProcessVersion -if "($ProcessVersion eq '11.0') || (!$ProcessVersion)"  y:\!temp\Test4.jpg
    1 files failed condition

C:\>exiftool -G1 -a -s -filename -ProcessVersion -if "(defined $ProcessVersion and $ProcessVersion eq '11.0') || (!$ProcessVersion)"  y:\!temp\Test4.jpg
[System]        FileName                        : Test4.jpg
* 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).

Phil Harvey

Or more simply: -if "not $ProcessVersion or $ProcessVersion eq '11.0'"

If you do it this way the eq won't be evaluated if $ProcessVersion is false.  Also, the super-low-precedence "or" operator makes brackets unnecessary.

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

RobiWan

Thanks - but In both variants, you first check whether $ProcessVersion exists. If you swap it, you will always get failed condition .

For now I have my solution  ;D