我有此代码:
@echo off
cls
setlocal enableextensions enabledelayedexpansion
set count=0
REM Now this will work and it will display the items of my itemlist.txt in numerical order
for /F "tokens=*" %%a in ('type mydir\itemlist.txt') do (
set /a count+=1
echo !count!^) This is the item %%a
set counted[!count!]=%%a
)
REM This works fine and diplays items defined by their corresponding numbers
echo %counted[1]%
echo %counted[2]%
REM And I want to do something like this:
set /p newcount=Input the number of the item of your choice:
REM Tried something like this:
set chosenitem=%counted[!newcount!]%
REM And didn't worked. The following doesn't display anything...
echo %chosenitem%
pause
所以我的问题是,我怎样才能准确地将用户选择的数量插入到%counted%变量中?
答案 0 :(得分:0)
我发布帖子后立即发现:Echo batch file arrays using a variable for the index?
所以我已经测试过:
echo !counted[%newcount%]!
工作完美!