I have a batch script which founds which drive is carrying my folder (diskpart situation) and founding folder, then it lists the text files (for now its text) in that folder. Anyways the problem is while the batch is asking me to choose which one do i want to open, it works until 9. I can't even press 10 because when i press 1 it automatically opens the text file. How can i write 2 digit numbers? Because the folder always will change and the might be 30 choices. Here's my code;
@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
You can emulate two-digit entries (or even more) by using two (or more)
choicecommands. Downside: You always have to enter both (all) digits ( like01for the first choice). Of course, this means you have to validate the resulting input manually:I avoided array-like variables by doing the
dirtwice, assuming the content of the folder won't change during the input.