different execution result dependent on how file is specified

Started by Tillomar, March 07, 2020, 08:42:01 PM

Previous topic - Next topic

Tillomar

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

StarGeek

See Common Mistake #2 and the second sentence in the docs on the -r (recurse) option.

tl;dr Recurse only works when you use a directory.  Using a wildcard will pass only files in the current directory. 
"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

Tillomar

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: There aren't any wildcards, so I can't see the reasoning here.

So long,
Tillomar

Phil Harvey

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

StarGeek

Oops, my mistake.  I saw the wildcard and the -r and jumped to my conclusion without fully reading everything.
"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

Tillomar

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 (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


Phil Harvey

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

Tillomar

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

Phil Harvey

Hi Tillomar,

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

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