ExifTool Forum

ExifTool => Newbies => Topic started by: robertklink on March 31, 2021, 11:28:10 PM

Title: Exiftool command in Powershell: IF condition always failing
Post by: robertklink on March 31, 2021, 11:28:10 PM
The following exiftool cmd works fine in Windows CMD:

exiftool -Config C:\Users\rober\.Exiftool_config.txt -overwrite_original -r -m -if "$CustomModelName and $CustomModelName ne $Model" "-Model<$CustomModelName" <Dir>

Where I'm using the IF to check that $CustomModelName tag (User-Defined) exists and is NOT the same as the existing Model tag before I write it to the Model tag.

When I put it into a Powershell script, it runs but always fails the IF condition. When I remove the IF condition it does the write correctly, so I'm pretty sure it has something to do with the Exiftool vs Powershell "IF" syntax. But there's no error complaints from either. I've also tried just a basic IF "$CustomModelName" condition - same problem.

I know this isn't an Exiftool issue per se, but hope that someone in this community has a clue on this.

Title: Re: Exiftool command in Powershell: IF condition always failing
Post by: StarGeek on April 01, 2021, 12:48:50 AM
It has to do with the fact that quoting is different in PowerShell vs CMD.  PowerShell acts more like Linux/Mac shells in this regard.  Try swapping single/double quotes.
Title: Re: Exiftool command in Powershell: IF condition always failing
Post by: robertklink on April 04, 2021, 10:12:11 PM
That got me partway to success, but I was still having drive me batty problems with syntax of my IF conditions, and apparent 'dislike' for having ".....(P)....." in my directory path.

Ultimately resorted back to CMD batch world and got er done.