ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Harald on March 09, 2017, 10:09:59 AM

Title: IF clause not working correctly under Windows, works on Mac
Post by: Harald on March 09, 2017, 10:09:59 AM
I have the following statement working well on Mac, but ignoring the "flag" set by the -usercomment field and thus re-applying the script each time it runs to ALL files
WINDOWS:exiftool -m -if "not $usercomment eq 'processed'" "-xmp:description<${xmp:description} - ${xmp:location}, ${xmp:city}, ${xmp:country}; Photographer: ${xmp:creator}; ${exif:createdate}" -d %Y-%m -usercomment='processed' .
MAC: exiftool -m -if 'not $usercomment eq "processed"' '-xmp:description<${xmp:description} - ${xmp:location}, ${xmp:city}, ${xmp:country}; Photographer: ${xmp:creator}; ${exif:createdate}' -d %Y-%m -usercomment="processed" .

The idea obviously is to concatenate several fields into the description field, but only one time.
On Windows, even though the -usercomment field is updated, it re-runs the script.
Thanks a lot in advance for your help.
Title: Re: IF clause not working correctly under Windows, works on Mac
Post by: Phil Harvey on March 09, 2017, 10:49:29 AM
Your condition will fail if $userComment is not defined.  What you need is this:

-if 'not defined $userComment or $usercomment ne "processed"'

- Phil
Title: Re: IF clause not working correctly under Windows, works on Mac
Post by: Harald on March 10, 2017, 07:49:51 AM
Thanks a lot Phil. If I understand the command correctly, my command should have failed on the first run, when the -usercomment was not defined. Which it did not. What failed was ignoring processed files on the second run, where the -usercomment field was already set to "processed".
In any case of course good to include the extra clause to take care of undefined fields.

Unfortunately the "if" still does not work properly. Although the -usercomment field is set to "processed" the command goes through all images and re-writes the description, making it a longer each time and replicating photographer, etc.

Now I had an intuition and I replaced the single quotes in the 'processed' with doubled quotes "processed" in the IF clause. And tata, it worked. Strange enough the assignment -usercomment='processed' at the end of the command works even with single quotes. This Windows can drive one crazy ...

So, problem solved. Thanks a lot again for your help.

kind regards,
Harald
Title: Re: IF clause not working correctly under Windows, works on Mac
Post by: Harald on March 10, 2017, 09:11:48 AM
UPDATE: I am afraid that was not it. I have done more tests and the condition fails each time when I have it in double quotes ("processed"). I also removed the first part (unspecified) but it still failed.
Maybe I should mention that the script runs on Windows server, not Windows 7, 8 or 10?
So the summary is: with double quotes it fails each run, with single quotes it always runs.

I hope you can solve this riddle :)

Title: Re: IF clause not working correctly under Windows, works on Mac
Post by: Phil Harvey on March 10, 2017, 09:16:47 AM
On Windows, the command should be:

exiftool -m -if "not defined $usercomment or $usercomment ne 'processed'" "-xmp:description<${xmp:description} - ${xmp:location}, ${xmp:city}, ${xmp:country}; Photographer: ${xmp:creator}; ${exif:createdate}" -d %Y-%m -usercomment="processed" .

And you must double the "%" characters if run from a .bat file.

- Phil
Title: Re: IF clause not working correctly under Windows, works on Mac
Post by: Harald on March 14, 2017, 09:27:11 AM
Thanks a lot, Phil. That was the one "''" combination that I had not tried :)
Works just fine now.