Use Checklist to Run Selected Commands.
Posted: 12 Jan 2022 13:05
Good evening,
A VERY Happy New Year to one and all.
I have a .bat file that runs several commands one after the other. If I do not want to run a particular Command[s], I have to manually comment out that/those Commands before running the Script.
With this in mind, I decided to try and setup a checklist where I could select ONLY those that I wanted to run.
I have spent hours trying to investigate this [ I do not want to use PowerShell ], and I have come up with the following which I found and have slightly amended.
My intention is to obviously add this to the top of my existing code.
How can I now get it to run after the selection[s] have been made please?
I would be VERY grateful for help please.
Thanks.
A VERY Happy New Year to one and all.
I have a .bat file that runs several commands one after the other. If I do not want to run a particular Command[s], I have to manually comment out that/those Commands before running the Script.
With this in mind, I decided to try and setup a checklist where I could select ONLY those that I wanted to run.
I have spent hours trying to investigate this [ I do not want to use PowerShell ], and I have come up with the following which I found and have slightly amended.
My intention is to obviously add this to the top of my existing code.
How can I now get it to run after the selection[s] have been made please?
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "num=0"
for %%a in ("Option 1"
"Option 2"
"Option 3"
"Option 4"
"Option 5"
"Option 6"
"Option 7"
"Option 8"
"Option 9"
) do (
set /A num+=1
set "msg[!num!]=%%~a"
set "opt[!num!]= "
)
set "digits=0123456789"
:select
(
cls
echo. & echo Enter the actual Number to Check/Uncheck an Option, or X to EXIT . . . & echo.
for /L %%i in (1,1,%num%) do echo !digits:~%%i,1!. [!opt[%%i]!] !msg[%%i]!
)
choice /C !digits:~1,%num%!X /N > nul
if %ErrorLevel% gtr %num% goto :endSelect
set "sel=%ErrorLevel%"
if "!opt[%sel%]!" equ "X" (set "opt[%sel%]= ") else set "opt[%sel%]=X"
goto :select
:endSelect
echo. & echo.
for /L %%i in (1,1,%num%) do (
if "!opt[%%i]!" equ "X" (
echo %%i selected
)
)
Thanks.