Search code examples
windowsbatch-filewindows-10command-line-interfacemediainfo

BATCH | echo multiple variables to file


Directory contains 2 (or more) video files with any random names.

video1.mkv
video2.mkv

Need to find out duration of every video. To do that we use MediaInfo.

setlocal EnableDelayedExpansion

for %%a in (*.mkv) do (
  for /f "usebackq" %%a in (`"mediainfo --Inform=Video;%%Duration%% %%a"`) do set duration=%%a

  echo "!duration!" > "data.txt"
)

Problem is, it prints only 1 value/duration (I think for last file). It works, buy only for one file.

How do I make it work with all files present in directory?


Solution

  • just use >> instead of >, which appends instead of overriding

    setlocal EnableDelayedExpansion
    
    for %%a in (*.mkv) do (
      for /f "usebackq" %%a in (`"mediainfo --Inform=Video;%%Duration%% %%a"`) do set duration=%%a
    
      echo "!duration!" >> "data.txt"
    )