Click here to Skip to main content
15,885,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In the following batch script, I would like to be able to input multiple choice at a time from the menu. For example, choice 1, 3 and 5.

And make the /LOADFILES argument take only one item at a time using a loop :
@echo off 
setlocal 
set "loadfiles="
:AddSamples
cls
echo current loadfiles: %loadfiles:~1%
echo add sample number
echo 1 - Sample_01
echo 2 - Sample_02
echo 3 - Sample_03
echo 4 - Sample_04
echo 5 - Sample_05
echo A - All and Go
echo G - Done and Go
choice /c 12345AG /m "What is your choice? "
if %errorlevel% == 1 set "loadfiles=%loadfiles%;Sample_01.mp3
if %errorlevel% == 2 set "loadfiles=%loadfiles%;Sample_02.mp3
if %errorlevel% == 3 set "loadfiles=%loadfiles%;Sample_03.mp3
if %errorlevel% == 4 set "loadfiles=%loadfiles%;Sample_04.mp3
if %errorlevel% == 5 set "loadfiles=%loadfiles%;Sample_05.mp3
if %errorlevel% == 6 set "loadfiles=;Sample_01.mp3;Sample_02.mp3;Sample_03.mp3;Sample_04.mp3;Sample_05.mp3" & goto :continue
if %errorlevel% == 7 goto :continue
goto :AddSamples
:Continue
set "loadfiles=%loadfiles:~1%"
"%SystemDrive%\software\Viewer.exe" /LOADFILES=%loadfiles%


What I have tried:

I have no specific idea of about how to achieve this.
Any help would greatly help me improve my script.
Thank you.
Posted
Updated 3-Aug-20 6:05am
v5

You need to use the set and for commands to get and parse the values. The following example merely echoes them back to the console, but should give you the idea.
set /P choice=What are your choices?
echo %choices%
for %%i in (%choices%) do echo %%i

Note, the reply must be values separated by spaces, e.g. "1 3 6" .
 
Share this answer
 
Something very similar I did some time ago, below is an adaptation / merging with your code and also using for...

this is string
%errorlevel% == 1
and this is int comparation
%errorlevel% EQU 1


@echo off && setlocal enabledelayedexpansion

echo; & set _loadfiles=<nul
set "_Viewer=%SystemDrive%\software\Viewer.exe"
set "_msn_error=This option is not yet valid..."

:AddSamples
cls & color 0A & echo=
     
if defined _loadfiles (

     echo\ Current loadfiles: ^| !_loadfiles:;= ^|! ) 
	
echo\ Add sample number & echo\
     
for /L %%i in (1 1 6)do if %%~i equ 6 ( 
      
    echo\  A - All and Go 
    echo\  G - Done and Go & echo\
     
    )else <con: echo\  %%~i - Sample_0%%~i 
     
choice /c 12345AG /m "What is your choice? " 
          
    if !errorlevel! equ 6 (
         
        for /L %%i in (1 1 5)do set "_loadfiles=Sample_0%%i.mp3;!_loadfiles!"
		goto=:Continue
       
    )else if !errorlevel! leq 5  (
	     
	    set "_loadfiles=!_loadfiles!Sample_0!errorlevel!.mp3;"
		goto=:AddSamples
          
    )else if !errorlevel! equ 7 if not defined _loadfiles (
             
            color F4 & set /p "'=%_msn_error%" & goto=:AddSamples
			 
			)else echo\ & goto=:Continue

:Continue
"!_Viewer!" /LOADFILES=!_loadfiles:~0,-1!

rem :: more code here...
%__APPDIR__%timeout.exe -1 & endlocal & goto=:EOF
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900