이 배열로 파일을 읽어와 변수로 각 행을 지정하고 그들에게 명령 행에서
@echo off
set "File2Read=file.txt"
If Not Exist "%File2Read%" (Goto :Error)
rem This will read a file into an array of variables and populate it
setlocal EnableExtensions EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%File2Read%"') do (
set /a count+=1
set "Line[!count!]=%%a"
)
rem Display array elements
For /L %%i in (1,1,%Count%) do (
echo "Var%%i" is assigned to ==^> "!Line[%%i]!"
)
pause>nul
Exit
::***************************************************
:Error
cls & Color 4C
echo(
echo The file "%File2Read%" dos not exist !
Pause>nul
exit /b
::***************************************************
표시/대 '의 출력을 판독?'(은'대/F 찾는다 'setlocal /?'(지연된 확장에 대해 읽음) –
명령 출력에서 변수를 설정할 때 [Windows 일괄 처리 도움말]이 중복 될 수 있습니다 (http://stackoverflow.com)./questions/1746475/windows-batch-help-in-setting-a-variable에서 명령 출력). 조이의 대답을 읽어보십시오. – JosefZ