der*_*ugo 4 windows batch-file output
我必须将输出存储DIR在变量中。
它们都提供了与我现在正在使用的大致相同的答案:
%= Find the *.sln file and write its path to the file temp.temp =%
DIR /s/b *.sln > temp.temp
%= Read out the content of temp.temp again to a variable =%
SET /p texte=< temp.temp
%= Remove the temp.temp file =%
DEL temp.temp
%= Get only the filename without path =%
FOR %%A IN ("%texte%") DO (
SET Name=%%~nxA
)
Run Code Online (Sandbox Code Playgroud)
但在我的情况下,我敢肯定的输出中DIR /s/b *.sln会是百达一个一个班轮。对我来说,必须
a)将输出存储在一个外部文件中,以及
b)FOR在其上运行一个循环,虽然我已经知道它只有一行,但看起来有点丑陋。
有没有直接/简单的方法可以做到这一点?
for /f "delims=" %%a in ('dir /s /b *.sln') do set "name=%%a"
Run Code Online (Sandbox Code Playgroud)
确实是最有效的方法(您可以直接处理命令的输出,不需要临时文件)。
%name%将包含您文件的完整合格文件名(如果有多个,则包含最后一个文件)