Allowing multiple selections for users using a batch file

I want to create a batch script of Windows, through which it allows the user to enter several options at a time, and then after that the program will work.

Regarding this website ( Multiple selection menus in a batch file? ), I find out that it somehow works to allow multiple selection. However, this is done in bash scripts. For instance...

@echo off
setlocal enabledelayedexpansion

echo Which would you like to use?

echo 1. Hello.txt
echo 2. Byebye.txt
echo 3. ThisIsText.txt
echo 4. MyBatchScript.txt
echo 5. All

set /p op=Type the numbers of the names you want to use (separated by commas with no spaces. E.g: 1,3,2): 

It still works, inviting users to select one or more options.

for /f "delims=, tokens=1-5" %%i in ("op") do (
set i=%%i
set j=%%j
set k=%%k
set l=%%l
set m=%%m
)

, "op", i. , j, k, l m . , . , .

, ...

1 , "Hello.txt" (.)

echo This is complicated > Hello.txt

1 (, 1,2),

echo This is complicated > Hello.txt
echo This is complicated > Byebye.txt

"5", ( ). - This is complicated > Byebye.txt, Hello.txt ..

?

: - ? , . , . . : , -.

if %i%X neq X set last=1b & goto %i%
:1b
if %j%X neq X set last=2b & goto %j%
:2b
if %k%X neq X set last=3b & goto %k%
:3b
if %l%X neq X set last=4b & goto %l%
:4b
if %m%X neq X set last=%m% & goto %m%
goto next

:1
::Put the code for doing the first option here
goto %last%
:2
::Put the code for doing the second option here
goto %last%
:3
::Put the code for doing the third option here
goto %last%
:4
::Put the code for doing the fourth option here
goto %last%
:5
::Put the code for doing the fifth option here
goto %last%

, . 1,2,3 , , ?

0
2

, FOR ( no/F) , , :

@echo off
setlocal enabledelayedexpansion

echo Which would you like to use?

echo 1. Hello.txt
echo 2. Byebye.txt
echo 3. ThisIsText.txt
echo 4. MyBatchScript.txt
echo 5. All

:getOptions
set /p "op=Type the numbers of the names you want to use (separated by commas OR spaces): "
if "%op%" equ "" goto getOptions

if %op% equ 5 set op=1,2,3,4
for %%a in (%op%) do (
   echo Process option %%a
   call :option-%%a
)
goto :EOF

:option-1
echo 1. Hello.txt
exit /B

:option-2
echo 2. Byebye.txt
exit /B

:option-3
echo 3. ThisIsText.txt
exit /B

:option-4
echo 4. MyBatchScript.txt
exit /B
0

, ('%op'), ("%op"), (%op) .

: ("%op%")

for Commandline-Parameters <Percent><char>.

op "" <Percent><name><Percent>: %op%

0

All Articles