Author Topic: Need help with an if statement  (Read 1340 times)

Tarn

  • Full Member
  • ***
  • Posts: 93
Need help with an if statement
« on: March 16, 2013, 08:04:53 PM »
Hi Phil

What I am trying to do is find any file that is in the Adobe RGB color space that the original file name is incorrect.

I store the original file name, that the camera gives the file, in UserComment; and am searching on that tag.

The logic is: If Color space is “Adobe” RGB OR “Uncal”ibrated AND the first character in Usercomment is NOT “_” (an underscore) list the file name, and other info. In short, I want it to show the files that have an improper name stored in UserComment, and ignore the one that are properly named, or in the sRGB color space.

With that, below is a copy from the screen. As you can see there is a slight problem in that it keeps picking out a file that is properly named in UserComment and displaying it. Triple asterisks mark the file name that should not be in the list.

Code: [Select]
U:\Holding>et -filename -Usercomment -colorspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
101108-6641.NEF _DSC6641.NEF    Adobe RGB
P3138172.JPG    P3138172.JPG    sRGB
P3138172.orf    _3138172.ORF    sRGB
_3138171.jpg    P3138171.JPG    Uncalibrated
_3138171.ORF    _3138171.ORF    Uncalibrated

U:\Holding>Match

U:\Holding>et -if "${Colorspace;$_=substr($_,0,5)} eq 'Uncal' or ${Colorspace;$_=substr($_
,0,5)} eq 'Adobe' and ${UserComment;$_=substr($_,0,1)} ne '_'" -filename -Usercomment -col
orspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
_3138171.jpg    P3138171.JPG    Uncalibrated
_3138171.ORF    _3138171.ORF    Uncalibrated ***

U:\Holding>Match

U:\Holding>et -if "${Colorspace;$_=substr($_,0,5)} eq 'Adobe' or ${Colorspace;$_=substr($_
,0,5)} eq 'Uncal' and ${UserComment;$_=substr($_,0,1)} ne '_'" -filename -Usercomment -col
orspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
101108-6641.NEF _DSC6641.NEF    Adobe RGB ***
_3138171.jpg    P3138171.JPG    Uncalibrated

U:\Holding>Match

U:\Holding>et -if "${UserComment;$_=substr($_,0,1)} ne '_' and ${Colorspace;$_=substr($_,0
,5)} eq 'Uncal' or ${Colorspace;$_=substr($_,0,5)} eq 'Adobe'" -filename -Usercomment -colorspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
101108-6641.NEF _DSC6641.NEF    Adobe RGB ***
_3138171.jpg    P3138171.JPG    Uncalibrated

U:\Holding>Match

U:\Holding>et -if "${UserComment;$_=substr($_,0,1)} ne '_' and ${Colorspace;$_=substr($_,0
,5)} eq 'Adobe' or ${Colorspace;$_=substr($_,0,5)} eq 'Uncal'" -filename -Usercomment -col
orspace . -T
101108-6639.NEF PDSC6639.NEF    Adobe RGB
101108-6641.JPG PDSC6641.JPG    Uncalibrated
_3138171.jpg    P3138171.JPG    Uncalibrated
_3138171.ORF    _3138171.ORF    Uncalibrated ***

U:\Holding>

In the first two checks the “and” clause was at the end. In the second two, I moved it to the beginning. In all four cases, it looks as if it is ignoring the first “if” clause. The one before the “or” statement.

If I use either of the clauses that check ColorSpace, with the "and" clause, that checks for something other than the "_" as the first character of UserComment, they work fine. It is when I try to join them with the "or" statement that it falls apart.

What am I messing up?

TIA

 


Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14733
    • ExifTool Home Page
Re: Need help with an if statement
« Reply #1 on: March 16, 2013, 09:04:04 PM »
The operator precedence of the logical "and" and "or" is messing you up.  "and" is higher precedence than "or", so the order doesn't matter and the "and" is evaluated first.  You need brackets if you want a different order.

But you can simplify what you have done using (gasp) regular expressions:

et -if "$Colorspace =~ /^(Adobe|Uncal)/ and $UserComment !~ /^_/" -filename -Usercomment -col
orspace . -T


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Tarn

  • Full Member
  • ***
  • Posts: 93
Re: Need help with an if statement
« Reply #2 on: March 17, 2013, 01:44:41 PM »
That's CHEATING!!! You know how to speak this language... I don't. :D

That works perfectly. Thanks.