Author Topic: Use of -if EXPR in windows  (Read 3632 times)

icom

  • Jr. Member
  • **
  • Posts: 14
Use of -if EXPR in windows
« on: December 05, 2012, 11:20:42 AM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 19109
    • ExifTool Home Page
Re: Use of -if EXPR in windows
« Reply #1 on: December 05, 2012, 11:31:33 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

icom

  • Jr. Member
  • **
  • Posts: 14
Re: Use of -if EXPR in windows
« Reply #2 on: December 05, 2012, 03:48:56 PM »
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

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 6324
Re: Use of -if EXPR in windows
« Reply #3 on: December 05, 2012, 04:51:51 PM »
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"
« Last Edit: December 05, 2012, 05:17:30 PM by StarGeek »
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 19109
    • ExifTool Home Page
Re: Use of -if EXPR in windows
« Reply #4 on: December 05, 2012, 07:13:11 PM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

icom

  • Jr. Member
  • **
  • Posts: 14
Re: Use of -if EXPR in windows
« Reply #5 on: December 06, 2012, 04:27:53 PM »
Thanks to both of you, StarGeek and Phil!

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

Regards, icom