Batch - Write output of DIR to a variable

后端 未结 1 909
囚心锁ツ
囚心锁ツ 2021-01-12 03:51

I have to store the ouput of DIR in a variable.

This was asked before e.g. here or here or here.

They all provide an answer more or less similar

1条回答
  •  -上瘾入骨i
    2021-01-12 04:54

    for /f "delims=" %%a in ('dir /s /b *.sln') do set "name=%%a"
    

    indeed is the most efficient method (you can process the output of a command directly, no need for a temporary file).
    %name% will contain the full qualified file name of your file (or the last of the files, if there are more than one)

    0 讨论(0)
提交回复
热议问题