编写批处理脚本来查找正确的文件。
dir /o:-d /a:-d F:\ | findstr /i ".target."
有上面的脚本,我的目标是只有第一个文件,并想存储文件名以供以后脚本使用。
有谁知道如何获取第一个文件并设置为 var?
编写批处理脚本来查找正确的文件。
dir /o:-d /a:-d F:\ | findstr /i ".target."
有上面的脚本,我的目标是只有第一个文件,并想存储文件名以供以后脚本使用。
有谁知道如何获取第一个文件并设置为 var?
Here's one example for retrieving the first line of your slightly modified command line, and save the line into a variable line1
. The /b
parameter is added onto dir
command, since we only want the file name. The |
character in the command line also needs to be escaped by a ^
character.
@echo off
setlocal
set line1=
for /f "tokens=* delims=" %%A in ('dir /o:-d /a:-d /b F:\ ^| findstr /i ".target."') do (
set line1=%%A
rem exit loop immediately once we got the line
goto next
)
:next
if "%line1%" != "" (
echo First Line:
echo %line1%
) else (
echo No file is found
)