0

I'm trying to get the dimensions width/height from a webp image, using exiftool via a batch file and saving those values as variables. I can get the bat file to output the dimensions (in this example it outputs "400x222" in the exiftool window), however I'm not too sure how to redirect those values sucessfully back inside the bat file console window as variables.

Below code gives me what I want, but in the exiftool window:

@echo off
setlocal EnableDelayedExpansion
echo ===============     WEBP EXIF    ===============
echo.

for %%f in ("C:\ffmpegConvert\*.webp") do (

    exiftool -k -s -s -s -ImageSize %%f

)

endlocal
pause
exit

Below is what I tried, but I'm not able to echo back those values in my initial bat file console window (I get "echo is off, once for each failed echo")

@echo off
setlocal EnableDelayedExpansion
echo ===============     WEBP EXIF    ===============
echo.

for %%f in ("C:\ffmpegConvert\*.webp") do (

    for /f "tokens=1,2 delims=x" %%a in ('exiftool -s -s -s -ImageSize %%f') do (
        set sW=%%a 
        set sH=%%b
    )
    @echo !sW! >CON:
    @echo !sH! >CON:
)

endlocal
pause
exit
  • 1
    Cannot duplicate here. You should replace `%%f` with `"%%~f"` on the `exiftool` command line to cover the case of paths with spaces, but other than that it is working for me as posted. – dxiv Jun 22 '20 at 02:49
  • @GeneralKnox What happened with `exiftool` option `-k` in second batch file? Why is `-s` specified three times? You see, I don't have installed `exiftool` and I don't have read its documentation. It could be that `exiftool` outputs the data to handle __STDERR__ instead of __STDOUT__ and so required is `'exiftool.exe -k -s -s -s -ImageSize "%%f" 2^>^&1'` to get the output correct captured and processed by inner `for`. I recommend to read about __issue 7__ in [this answer](https://stackoverflow.com/a/60686543/3074564) and use `I` and `J` (and `K`) as loop variables instead of `f`, `a` (and `b`). – Mofi Jun 22 '20 at 06:04
  • Ok thanks to all, and I made the changes you suggested as well (dixv + Mofi). I bookmarked your links Mofi, thanks for that! I am really enjoying learning about scripting in general, so much fun! – General Knox Jun 22 '20 at 12:24
  • @Mofi The reason `-s` is listed three times is so it prints only the value of the tag without any extra data such as the tag name. It can also be listed as `-s3` to achieve the same result. See the docs on the [`-s` (`-short`) option](https://exiftool.org/exiftool_pod.html#s-NUM--short). – StarGeek Jun 22 '20 at 14:46

1 Answers1

0

Ok, so after checking out all your feedback and doing some extra googling, I noticed that my exiftool.exe in c:\Windows had "run as admin" checked in its properties. Unticking this option now returns the variables in my original console...To be sure, I re-checked it, and it went back to not displaying the info properly. I don't understand why that is, but now it works as I wanted:) Thanks again for your responses!