I haven't found a good choice example on the web. I had to format it like this. Can anyone get the message in line with the choice option;
echo Would you like to set folders to exclude?
CHOICE /T 4 /C ync /CS /D n
if errorlevel=3 goto variables
if errorlevel=2 goto backup
if errorlevel=1 goto exclude
echo Something is wrong
I also found selecting the last option "c", errorlevel is both 1,2&3 (sigh)
I would like to use set /p choice.... like;
set /p userinp=Choose a number (1-6):
or
set /P c=Did you run as administrator? Y/N?....
I appreciate your help.
set /p choice /t prompt? correct format
Moderator: DosItHelp
Re: set /p choice /t prompt? correct format
Try without the =
Code: Select all
Choice /T 4 /C ync /CS /D n /N /M "Press y for Yes, n for No or c for Cancel."
If ErrorLevel 3 GoTo variables
If ErrorLevel 2 GoTo backup
If ErrorLevel 1 GoTo exclude
Echo(Something is wrong
-
- Posts: 20
- Joined: 25 May 2012 12:34
Re: set /p choice /t prompt? correct format
Thank you, that was simple enough.
Is there a way to use the Set /p so I can test Y or N instead of errorlevel?
Is there a way to use the Set /p so I can test Y or N instead of errorlevel?
Re: set /p choice /t prompt? correct format
You test for the errorlevel using Choice
To use Set
Code: Select all
Choice /T 10 /C YN /D N /N /M "Press Y for Yes or N for No."
If ErrorLevel 2 GoTo ChoseN
Echo( Yes was chosen.
GoTo EndMe
:ChoseN
Echo( No was chosen.
:EndMe
Pause
To use Set
Code: Select all
@Echo Off
SetLocal
:Loop
Cls
Set "Opt="
Set/P "Opt=Press Y for Yes or N for No. "
If /I "%Opt%" NEq "N" (If /I "%Opt%" NEq "Y" GoTo :Loop) Else (GoTo ChoseN)
Echo( Yes was chosen.
GoTo EndMe
:ChoseN
Echo( No was chosen.
:EndMe
Pause
Re: set /p choice /t prompt? correct format
IF command requires two equal signs for string comparisons.