windowsbatch-filefilenamesffprobeminus

Windows batch and ffprobe -- problem with filenames starting with "-"


If the file name (%F) starts with a "-" character, the file is not found by ffprobe.exe (the file name from the next character after "-" is passed to ffprobe).

How to save this correctly?

for /f %%i in ('ffprobe -v error -select_streams v:0 -show_entries stream^=height -of csv^=s^=x:p^=0 "%%F"') do set hgt=%%i

I expected the full file name to be passed to ffprobe.exe, e.g. "- 7.06.2022.mpg"


Solution

  • Use the -- flag at the end of the command before the filename to indicate to ffprobe that there are no more flags expected and that any additional leading dashes are part of the filename.

    for /f %%i in ('ffprobe -v error -select_streams v:0 -show_entries stream^=height -of csv^=s^=x:p^=0 -- "%%F"') do set hgt=%%i