【发布时间】:2018-05-07 03:01:56
【问题描述】:
我必须将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
)
但就我而言,我确信DIR /s/b *.sln 的输出总是单行。对我来说,不得不这样做看起来有点难看
a) 将输出存储在外部文件中,然后
b) 在它上面运行一个FOR 循环,虽然我已经知道它只有一行。
是否有任何直接/更简单的方法可以做到这一点?
【问题讨论】:
标签: windows batch-file output