Batch file to select multiple option/choice in a batch file and execute the task assigned to it

83 Views Asked by At

I want to create a batch file in which I have selected an choice and after selection it executes the task. What I'm expecting is to create another choice within a choice where it will ask me to enter a number and based on the number the task will be executed.

@ECHO off
cls
:start

title [ Lazy Planner]

ECHO ===========================================================================================
ECHO.
type "C:\Automation\doh.txt"             
ECHO.
ECHO ===========================================================================================
ECHO.
ECHO 1. WSR Report Folder Path                                                                    
ECHO.
ECHO 2. Availability-Capacity Deck Folder Path
ECHO.
ECHO 3. Pre-CAB Checklist Folder Path
ECHO.
ECHO 4. Exit Lazy Planner
ECHO.

ECHO **************************************
set /p choice= Welcome! Please enter your choice: 
rem if not '%choice%'=='' set choice=%choice:~0;1% ( don`t use this command, because it takes only first digit in the case you type more digits. After that for example choice 23455666 is choice 2 and you get "bye"
if '%choice%'=='' ECHO "%choice%" is not valid please try again
if '%choice%'=='1' start "\\Dell_BOI_MASS\Weekly Status Report\Work In Progress Report\" "\\Dell_BOI_MASS\Weekly Status Report\Work In Progress Report\"
if '%choice%'=='2' start "\\Dell_BOI_MASS\Service Design\Availability\Priyanka\2023\April2023\" "\\Dell_BOI_MASS\Service Design\Availability\Priyanka\2023\April2023\"
if '%choice%'=='3' start "\\Dell_BOI_MASS\Change Management\PRE PreCAB Quality Checks\Today\" "\\Dell_BOI_MASS\Change Management\PRE PreCAB Quality Checks\Today\"
if '%choice%'=='4' goto Exit

?

1

There are 1 best solutions below

0
SeanMrnd On

You werent far off of something usuable so im not 100% sure if this is what you are asking for but try this. hitting enter instead of typing anything sets the selection to default to nothing

@echo off
title [Lazy Planner]     
ECHO ===========================================================================================
ECHO 1. WSR Report Folder Path                                                                    
ECHO 2. Availability-Capacity Deck Folder Path
ECHO 3. Pre-CAB Checklist Folder Path
ECHO 4. Exit Lazy Planner
ECHO ===========================================================================================
set /p "Selection=Welcome^! Please Enter Your Selection: " || set "Selection=nothing"
if "%Selection%"=="nothing" ECHO "%Selection%" is not valid please try again
if "%Selection%"=="1" start thing 1
if "%Selection%"=="2" start thing 2
if "%Selection%"=="3" start thing 3
if "%Selection%"=="4" goto Exit