Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

windows - Batch scripting multiple selection

how do you allow the user to type multiple numbers into batch scripting if prompted?

if it prompted 5 options to the user. And the user wanted to choose 1,2,3 but does not want 4,5, how to do it in batch scripting?

I refered to Allowing multiple choice selections for users using batch file and Multiple choices menu on batch file?

There is relevant questions in stackoverflow but there is no answer to it because the answer is not right to the point.

Any help would be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This answer also refers to this question: How to integrate batch script multiple selections into JAVA GUI?

You might like to add a line at the top to delete family.txt if you want a new file each time.

@echo off
echo.
echo Selection time!
echo.
echo 1. My father is Joe
echo 2. My mother is Audrey
echo 3. My brother is Jerry
echo 4. My elder sister is June
echo 5. My youngest sister is Awy
echo 6. Include All
echo.

:getOptions
set "choices="
set /p "choices=Type your choices without spacing (e.g. 1,2,3): "

if not defined choices ( 
    echo Please enter a valid option
    goto getOptions
    )

for %%a in (%choices%) do if %%a EQU 6 set choices=1,2,3,4,5
for %%i in (%choices%) do call :option-%%i

echo.
echo Done
pause
exit

:option-1
>> Family.txt echo My father is Joe
exit /B

:option-2
>> Family.txt echo My mother is Audrey
exit /B

:option-3
>> Family.txt echo My brother is Jerry
exit /B

:option-4
>> Family.txt echo My elder sister is June
exit /B

:option-5
>> Family.txt echo My youngest sister is Awy
exit /B

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...