ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: Tillomar on March 07, 2020, 08:42:01 PM

Title: different execution result dependent on how file is specified
Post by: Tillomar on March 07, 2020, 08:42:01 PM
I thing I'm looking at a bug -- but the problem may well sit in front of the keyboard. So please help me out...

I made an arguments file with the following contents:


    -echo
        * SPECIAL: correct malformed Android images
    -overwrite_original
    -if
        not $Createdate
    -if
        $filename;m/IMG-\d{8}-WA\d{4}\.jpg/i
    -r
    -p
        $filename
    -ext
        jpg


This shall catch (or later on correct -- this example is a stripped down version for debugging) certain jpg image files with a special filename pattern, and missing the CreateDate tag. Also for debugging purposes I just print the filename.

ExifTool is then executed, in a folder containing seven image files, like this: exiftool -@ parameter_photo_special.txt -common_args .
or even: exiftool -@ parameter_photo_special.txt .

In both cases the result is:


Exiftool Configuration file loaded!
* SPECIAL: correct malformed Android images
    1 directories scanned
    7 files failed condition
    0 image files read


But there are two files present which (should) match the condition; commenting out the filename pattern check results in:


Exiftool Configuration file loaded!
* SPECIAL: correct malformed Android images
IMG-20200219-WA0004.jpg
IMG-20200219-WA0008.jpg
    1 directories scanned
    5 files failed condition
    2 image files read


Given the filenames shown, I can't see a reason why my -if $filename;m/IMG-\d{8}-WA\d{4}\.jpg/i condition should fail.
And indeed, with the filename pattern check in place, and called like this:
exiftool -@ parameter_photo_special.txt "IMG-20200219-WA0004.jpg" "IMG-20200219-WA0008.jpg"

the result is as expected:


Exiftool Configuration file loaded!
* SPECIAL: correct malformed Android images
IMG-20200219-WA0004.jpg
IMG-20200219-WA0008.jpg
    2 image files read


I'm stumped; Anyone any idea?

Thanks in advance!
Tillomar


Addon: Using Win7-64, Exiftool v11.87
Title: Re: different execution result dependent on how file is specified
Post by: StarGeek on March 07, 2020, 09:06:38 PM
See Common Mistake #2 (https://exiftool.org/mistakes.html#M2) and the second sentence in the docs on the -r (recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse).

tl;dr Recurse only works when you use a directory.  Using a wildcard will pass only files in the current directory. 
Title: Re: different execution result dependent on how file is specified
Post by: Tillomar on March 08, 2020, 09:29:49 AM
You are indeed right that the -r (recurse) option is useless in my last test using fully qualified file names, but as far as I can see it does no harm, either.
Just to be sure, I redid the tests less the -r option -- without any change in results...

Regarding wildcards and common mistake #2 (https://exiftool.org/mistakes.html#M2): There aren't any wildcards, so I can't see the reasoning here.

So long,
Tillomar
Title: Re: different execution result dependent on how file is specified
Post by: Phil Harvey on March 08, 2020, 09:41:37 AM
Hi Tillomar,

Your -if condition line should be:

$filename =~ m/IMG-\d{8}-WA\d{4}\.jpg/i

(ie. you need to use the binding operator, =~, instead of a semicolon)

- Phil
Title: Re: different execution result dependent on how file is specified
Post by: StarGeek on March 08, 2020, 11:22:14 AM
Oops, my mistake.  I saw the wildcard and the -r and jumped to my conclusion without fully reading everything.
Title: Re: different execution result dependent on how file is specified
Post by: Tillomar on March 08, 2020, 12:35:01 PM
Hi Phil,

thanks, that did it...

I fear that this goes into Perl programming, but anyway -- would you please care to explain to me the why?

EDIT: And I wonder why it depends on whether I specify the fully qualified file name or just the folder name?

Trying not make you have to start at adam&eve, I took your answer as a starting point and looked up the binding operator, and came upon an explanation that "using the binding operator would allow not to use $_". That in itself had been a mystery to me, neither researched nor understood yet but already used, as I ignorantly took some code from the forum (https://exiftool.org/forum/index.php?topic=8703.msg44649#msg44649) (hi StarGeek -- that was your code :) ) for exactly this task of fixing the malformed Android images:


    -alldates<${filename;m/IMG-(\d{4}\d{2}\d{2})-WA\d{4}\.jpg/;$_=$1} 00:00:00
    -filename<${filename;m/IMG-\d{4}\d{2}\d{2}-(WA\d{4})\.jpg/;$_=$1}.%le


(Please ignore me splitting the digit groups w/i the captureing group...)

Comparing this code, my old compare expression and your advised correction makes my head spin. I understand that {...;m/.../;$_=$1} sets a new result from the first matching group, but how that works together I'm still unclear; I think I simply don't know how the regex operator (function? procedure?) works (not the regex itself, that's fine).

Thanks,
Tillomar

Title: Re: different execution result dependent on how file is specified
Post by: Phil Harvey on March 08, 2020, 08:44:56 PM
Hi Tillomar,

First, don't get confused by the different requirements of the Perl expression in a -if argument (which uses tag names as Perl variables) and the advanced formatting expression (which only uses $_).  The binding operator is used to apply a regular expression to a variable, but if no variable is specified then $_ is assumed (ie. "$_ ~= EXPR")

- Phil
Title: Re: different execution result dependent on how file is specified
Post by: Tillomar on March 09, 2020, 11:26:43 AM
Hi Phil,

Quoterequirements of the Perl expression in a -if argument which uses tag names as Perl variables
vs.
Quoteadvanced formatting expression which only uses $_

I will research those points. I got me the "liama", so it should "only" be a question of time spent...  ;)
What still is not clear: Why the different behavior? I would have expected the wrong condition to fail always, but given full filenames, it works -- or at least, it seems that way, but maybe my test is not sufficient.

So long,
Tillomar
Title: Re: different execution result dependent on how file is specified
Post by: Phil Harvey on March 09, 2020, 11:31:50 AM
Hi Tillomar,

It shouldn't have worked with either relative or full filenames.  I think you were fooling yourself.

- Phil