我在此主题上找到了帮助。用户:Hackoo有很多代码。我在文本文件上运行它,并按预期创建了5个不同的变量。它工作完美。我想知道如何提示用户选择他们想要保留的变量。然后将输入内容放在一个单独的文本文件中。那可能吗?这是用于获取变量的代码。
@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
::***************************************************