return true, if tag does not exist or does not have a specific value

Started by c6y, March 25, 2017, 05:01:58 PM

Previous topic - Next topic

c6y

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!

StarGeek

Try
-if 'not $XMP-cc:AttributionName =~ /myname/ or not defined $XMP-cc:AttributionName'
"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

Phil Harvey

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

c6y

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! :)

Hayo Baan

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/'
Hayo Baan – Photography
Web: www.hayobaan.nl