Exiftool command in Powershell: IF condition always failing

Started by robertklink, March 31, 2021, 11:28:10 PM

Previous topic - Next topic

robertklink

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.


StarGeek

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.
"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

robertklink

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.