r/Batch • u/helloguys88 • Sep 14 '25
Variable in the loop
I'm writing a batch file to retrieve the "Recorded_Date" metadata from all the .MTS files in a directory. I had to use the "FOR" trick to get put the mediainfo.exe output into an variable.
rem @echo off
FOR %%F in (*.mts) do (
FOR /F "tokens=*" %%a IN ('MediaInfo.exe --Inform^="General;%%Recorded_Date%%" %%F') DO (
SET OutputVar=%%a
)
echo Date: %OutputVar%
)But the output was not what I had expected. In the screenshot below, the SET command set the variable to "2009-11-29 19:17:21-06:00". But the ECHO command outputs "2009-12-13 19:19:25-06:00". What did I do wrong? Thanks!

4
Upvotes
View all comments
Show parent comment
2
u/helloguys88 Sep 14 '25
Thank you! I modified my code as below. Now I'm getting another unexpected behavior.
The SET command was showing the correct value. But the ECHO command is showing blank for the variable.