批处理文件选择命令多于 10 个参数

Batch file choice command more than 10 parameter

我有一个批处理脚本,它可以找到哪个驱动器正在承载我的文件夹(diskpart 情况)和创建文件夹,然后它列出该文件夹中的文本文件(现在是文本)。无论如何,问题是当批处理要求我选择我想打开哪个时,它一直工作到 9。我什至不能按 10,因为当我按 1 它会自动打开文本文件。我怎样才能写出两位数?因为文件夹总是会改变,而且可能有 30 个选择。这是我的代码;

@for %%a in ( C D E F G H I J K L M N O P Q R S T U V W X Y Z ) do @if exist %%a:\TAM_IMAGES set The_Drive=%%a
@for %%b in ( C D E F G H I J K L M N O P Q R S T U V W X Y Z ) do @if exist %%b:\Users\canoca\Desktop\bosluktesti set testbasarisiz=%%b
REM @dir %The_Drive%:\TAM_IMAGES
REM @dir %testbasarisiz%:\Users\canoca\Desktop\bosluktesti
cd %The_Drive%:\TAM_IMAGES
setlocal enabledelayedexpansion

set count=0
set "choice_options="

for /F "delims=" %%A in ('dir /a:-d  /b "%The_Drive%:\TAM_IMAGES"') do (

   set /a count+=1

   set "options[!count!]=%%A"

   set choice_options=!choice_options!!count!
)

for /L %%A in (1,1,!count!) do (
   echo %%A]- !options[%%A]!
   
)

choice /c:!choice_options!  /m "Yuklemek istediginiz imaji seciniz: "

REM %testbasarisiz%:\Users\canoca\Desktop\test.bat %The_Drive%:\TAM_IMAGES\!options[%ERRORLEVEL%]!


start %The_Drive%:\TAM_IMAGES\!options[%ERRORLEVEL%]!

cmd /k

您可以使用两个(或更多)choice 命令模拟两位数(或更多)条目。缺点:您总是必须输入两个(所有)数字(例如 01 作为第一个选择)。当然,这意味着您必须手动验证结果输入:

@echo off
setlocal enabledelayedexpansion

:input
set count=100
for /f "delims=" %%a in ('dir /b /a-d') do (
  set /a count+=1
  echo !count:~-2!] %%a
)
set /a countMax=count-100
set "countNr=%count:~-2%"
<nul set /p "=input (01...%countNr%, 00 for exit): " 
choice /c 1234567890 /n >nul
set first=%errorlevel:~-1%
<nul set /p "=%first%"
choice /c 1234567890 /n >nul
echo %errorlevel:~-1%
set ch=%first%%errorlevel:~-1%
echo that was %ch%
set /a line=1%ch%-101

REM echo debug: ch=%ch%;CountNr=%countNr%;CountMax=%CountMax%,Line=%line%
if "%ch%" == "00" goto escape
if %ch% gtr %countMax% echo bad input&goto :input

for /f "delims=" %%a in ('dir /b /a-d^|more +%line%') do set "file=%%a"&goto :cont
:cont
echo that was %ch% - %file%
echo doing something with %file%.
goto :eof

:escape
echo you choosed '00' for exit.

我通过执行两次 dir 避免了类似数组的变量,假设文件夹的内容在输入过程中不会改变。