Page 1 of 1

set /p choice /t prompt? correct format

Posted: 01 Feb 2015 14:38
by crobertson
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.

Re: set /p choice /t prompt? correct format

Posted: 01 Feb 2015 15:12
by Compo
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

Re: set /p choice /t prompt? correct format

Posted: 01 Feb 2015 15:58
by crobertson
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?

Re: set /p choice /t prompt? correct format

Posted: 01 Feb 2015 16:53
by Compo
You test for the errorlevel using Choice

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

Posted: 01 Feb 2015 17:52
by Squashman
IF command requires two equal signs for string comparisons.