Author Topic: Calling exiftool more than once in a batch file  (Read 92 times)

mblanchette

  • Newbie
  • *
  • Posts: 4
Calling exiftool more than once in a batch file
« on: January 20, 2020, 10:09:59 AM »
Hello,

I pologize if this is a  post - I thought I posted it last night, but now I don't see it.

Is it possible to write a batch file to run exiftool multiple times to rename files based on different conditions, where in some cases more than one condition is true for the same file?  I have a batch file at the end, but when I run this, it goes thru all files, and in each case, stops after the first true "if" statement.  Is it possible to do all of this in one file, or do I have to create a batch file for each and then wrap another batch file around them (I haven't tried that yet, so I don't even know if it will work).  Anyway, here is the batch fle.  Thanks!

rem @echo off

exiftool "-filename=%%f_PixelShift.%%e" -if "$PixelShiftResolution eq 'On'" *

rem HDR will start with HDR if on:
exiftool "-filename=%%f_HDR.%%e" -if "$HDR lt 'Off'" *

exiftool "-filename=%%f_flash.%%e" -if "$flash ge 'On'" *




StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 3129
Re: Calling exiftool more than once in a batch file
« Reply #1 on: January 20, 2020, 11:36:48 AM »
Just to clarify, does your batch file completely stop after the first command?  In other words, do you only get one listing of
1 directories scanned
  ### files failed condition
  ### image files read


Or do you get three listings of that but no files affected?

Are you running in CMD or Powershell?  PS acts weird with exiftool commands that have a $ in them.

There's no reason for a batch file to exit after the first command unless something else is going on.

Have you tried testing your command individually outside the batch to see if they produce the expected results?  For example, your second command will return true (under Windows, maybe not under Mac/Linux) in cases where HDR doesn't exist, resulting in a name of "File_.jpg"
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.

mblanchette

  • Newbie
  • *
  • Posts: 4
Re: Calling exiftool more than once in a batch file
« Reply #2 on: January 21, 2020, 01:51:07 PM »
Hello,

When I run it as part of one batch, I see the results of all three calls, but files seem to only get renamed based on the first condition they conform to.  Realistically that is not a big issue - files in my test set meet multiple conditions, but, in the real worlds, this is extremely unlikely for the conditions I am looking at.  If this changes down the road, I might try something like this:

exiftool -if "$Model eq 'NIKON D200'"  -Nikon:CameraSerialNumber=6007814 -execute -if "$Model eq 'DSC-V3'"  -EXIF:CameraSerialNumber=7559435 -common_args DIR

I also tried splitting it into three batch files, which seems to work.  Also, this:
     exiftool "-filename=%%f_HDR.%%e" -if "$HDR lt 'Off'" *
is counterintuitive, but this tag actually contains a string starting with "HDR" if on and "Off" if not - so on < off.

Thanks