0

我只想读取批处理文件中的前两行并将它们存储在两个不同的变量中。我使用了这段代码:

@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”显示为空白。关于如何去做的任何想法?

4

1 回答 1

1

您的尝试有点矫枉过正,语法错误。

试试这个

<red.txt (
  set /p line1=
  set /p line2=
)
echo line1=%line1% 
echo line2=%line2%
于 2012-10-11T07:01:22.423 回答