我只想读取批处理文件中的前两行并将它们存储在两个不同的变量中。我使用了这段代码:
@echo off
for /f "delims=''" %%f in (red.txt) do (
echo file is: %%f
set /A Counter+=1
call :a %counter%
echo Counter After Increment: %Counter%
echo.
)
:a
if %Counter% equ 1 (set "file1=%f"
echo first file is: %file1%)
if %Counter% equ 2 (set "file2=%f"
echo second file is: %file2%)
if %Counter% equ 4 exit
echo Counter after for loop: %Counter%
pause
但变量“file1”和“file2”显示为空白。关于如何去做的任何想法?