ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: c6y on March 25, 2017, 05:01:58 PM

Title: return true, if tag does not exist or does not have a specific value
Post by: c6y on March 25, 2017, 05:01:58 PM
I'd like this to return true — if a tag doesn't exist OR if the value of the tag is not 'myname'.

See below for what I have. But I'm getting a false even if tag XMP-cc:AttributionName does not exist.

exiftool \
  -r \
  -if 'not $XMP-cc:AttributionName =~ /myname/' \
  -FileName \
  .


Thanks!
Title: Re: return true, if tag does not exist or does not have a specific value
Post by: StarGeek on March 25, 2017, 06:36:32 PM
Try
-if 'not $XMP-cc:AttributionName =~ /myname/ or not defined $XMP-cc:AttributionName'
Title: Re: return true, if tag does not exist or does not have a specific value
Post by: Phil Harvey on March 25, 2017, 10:19:24 PM
Quote from: StarGeek on March 25, 2017, 06:36:32 PM
-if 'not $XMP-cc:AttributionName =~ /myname/ or not defined $XMP-cc:AttributionName'

I would recommend reversing the order since the =~ may fail if the tag is not defined:

-if 'not defined $XMP-cc:AttributionName or not $XMP-cc:AttributionName =~ /myname/'

- Phil
Title: Re: return true, if tag does not exist or does not have a specific value
Post by: c6y on March 25, 2017, 11:09:02 PM
Big thanks Phil & StarGeek! I was not aware that OR could be used. Somehow I missed to find it on the documentation. And the order turned out to be relevant as well! Thanks again! :)
Title: Re: return true, if tag does not exist or does not have a specific value
Post by: Hayo Baan on March 26, 2017, 08:04:24 AM
Quote from: Phil Harvey on March 25, 2017, 10:19:24 PM
I would recommend reversing the order since the =~ may fail if the tag is not defined:

-if 'not defined $XMP-cc:AttributionName or not $XMP-cc:AttributionName =~ /myname/'

And while you're at it, change not $XMP-cc:AttributionName =~ /myname/ into $XMP-cc:AttributionName !~ /myname/ :)

-if 'not defined $XMP-cc:AttributionName or $XMP-cc:AttributionName !~ /myname/'