Use of -if EXPR in windows

Started by icom, December 05, 2012, 11:20:42 AM

Previous topic - Next topic

icom

Hi,

im trying to modify a file depending on it's name, using the -if option. So all the files I want to modify have a name ending with the letter "g", e.g. "023 DSC1007g.jpg".
So from the exiftool documentation my understandig was, that the expression should read "%-1f eq 'g'" (Windows!), and the whole command e.g.
exiftool -make -if "%-1f eq 'g'" <directory>
for extracting the make of thes files. However,  I'm always ending up with "all files failed condition" (stating the number instead of "all") - what I'm doing wrong? I've tried all possible variations of " and ' - without success. So all ideas are welcome  ;)
(I'm using exiftool 9.03, Windows 7 64)

Kind regards,
icom

Phil Harvey

Hi icom,

Interesting, but the %f may not be used in a -if expression (which is a standard Perl expression).  Instead, do this:

-if "$filename =~ /g$/"

This is a regular expression (regex) to match a string with a last character of "g".

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

icom

Hi Phil,

thanks for your quick reply - unfortunately at least for the first try (copy and paste) ist doesn't work either - again "all files failed condition".
However, if %f cannot be used with -if, I have to do some updates on my experience with regular expressions - it's been quite a long time ...  8)

Could it also be a Windows topic (slash, back-slash, single quote, double quote, ...)?
And doesn't the tag "filename" also include the extension of the file? So it would always be a "g" because of <name.jpg>.  ;D

Regards, icom

StarGeek

#3
I previously had problems with using the $ in regexp under windows.  I found if I used parens as well it would work.
-if "$filename =~ /(g$)/"

The one problem I see here though is that $filename seems to include the extension.  The quick testing I just did showed that the above statement matched all .jpg files in the directory.

You might try
-if "$filename =~ /(g\.jpg$)/i"
I added the i at the end to make it case insensitive.

edit: Playing around with it some more and it it looks like doubling the $ also works.  Must be a windows command line thing.
-if "$filename =~ /g\.jpg$$/i"
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Thanks StarGeek, you're right, I got bitten by this one again:

Doubling the "$" is necessary because exiftool converts "$/" to a newline.  This is because it uses the same mechanism as -p to interpolate the tag names before evaluating the expression.  I should document this.

And yes, FileName does include the extension.  StarGeek has suggested a good way around this.

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

icom

Thanks to both of you, StarGeek and Phil!

Both solutions provided by StarGeek worked quite well! Thanks again!

Regards, icom