Dos Batch programming-Command line menus

         I have a user who wants to work down on the dos command
line rather than up at the graphic level for some tasks.   For this she
would like a little menu which would allow her to change to different
directories and start different programs based on inputting a
number from 1 to 9.
       Now this is ancient Dos batch programming and I just can't
seem to make the backwards leap to understand how to  write
the little file needed.   Can someone give me a hand on this?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You will probably need to use the Choice command to accomplish this.

C:\>choice /?
CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

/C[:]choices Specifies allowable keys. Default is YN
/N           Do not display choices and ? at end of prompt string.
/S           Treat choice keys as case sensitive.
/T[:]c,nn    Default choice to c after nn seconds
text         Prompt string to display

ERRORLEVEL is set to offset of key user presses in choices.

Otherwise, you may be able to find another menuing program to do this.
Okay, here's an example for your little batch...

_________CUT HERE___________
@echo off
echo Select the app to run
echo ----------------------
echo 1 Application One
echo 2 Application Two
echo 3 Yet Another application
echo --------------------
echo E Exit this menu

choice /C:123E Your choice

if ERRORLEVEL 4 goto :A0
if ERRORLEVEL 3 goto :A3
if ERRORLEVEL 2 goto :A2
if ERRORLEVEL 1 goto :A1

echo Starting app 1 .....
goto MM

echo Starting app 2....
call d:\somewere\else\is\app2.bat
goto MM

echo Starting app 3....
goto MM

echo Exitting, bye ........

____________CUT HERE_______________

It is really straightforward, for adding more applications just remember that the if ERRORLEVEL n statements need to be in DESCENDING order (the command jumps if the errorlevel is equal to or greater than the number specified).
The choice command is not limited to numbers only. I think it is better to use 'A' for Accounting, 'E' or 'Q' for Exit/Quit etc.

Instead of/ before starting an application, you can do e.g.
cd \accounting\1999

Feel free to post a comment if you need any more help with this.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OOOOOOPPSSS! Sorry, the lines below choice... should read:

if ERRORLEVEL 4 goto A0
if ERRORLEVEL 3 goto A3
if ERRORLEVEL 2 goto A2
if ERRORLEVEL 1 goto A1

(that is, without the colons....)
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

bwsaulAuthor Commented:

       It worked like a charm.

You're welcome... thanks for points :))

I've been working on a similar batch and as I'm using Windows XP - have had to resort to the SET command in place of the CHOICE command which isn't available.

@echo off
echo Select the app to run
echo ----------------------
echo 1 Application One
echo 2 Application Two
echo 3 Yet Another application
echo --------------------
echo E Exit this menu

set /p userinp=

if %userinp%==4 goto A0
if %userinp%==3 goto A3
if %userinp%==2 goto A2
if %userinp%==1 goto A1

And then the rest like show on joe_h's example above.

Also, I found applying the /I variable on the IF command quite useful when prompting a user for a Yes or No choice - it ensures the string is Case- Insensitive; meaning that if they are prompted to press Y or N, it doesn't matter if they type y or n.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.