Archive for the ‘DOS Batch Script’ Category

Make a menu in DOS Batch Script

星期日, 三月 7th, 2010
@echo off

rem Remarks can be added by rem
rem Text will not be echoed after the symbol @
rem @echo off can prevent any command from being displayed

rem Clear the screen
cls

rem Print the text "Game Menu" on the screen
echo Game Menu

rem To create a blank line
echo.

echo 1 - Game 1
echo 2 - Game 2
echo 3 - Game 3
echo 0 - Exit
echo.

rem To get a user input key definded after /c:
choice /c:1230 Press a number to enter game

echo.

rem The exit code of the command choice is stored in errorlevel,
rem and the exit code is the position index of the user input key
rem starting from 1. Note that errorlevel number is also true even
rem if the value of errorlevel is greater than the number specified.
rem i.e. If the value of errorlevel is greater than or equal to the
rem number specified, go to the label specified.
if errorlevel 4 goto end
if errorlevel 3 goto game3
if errorlevel 2 goto game2
if errorlevel 1 goto game1

rem Label can be defined by a colon following by a word
:game1
cd c:\game1
play
goto end

:game2
cd c:\game2
play
goto end

:game3
cd c:\game3
play
goto end

:end
echo.