DosTips.com ... for WinXP
Search:
Last update:
Dec 18, 2007

<<< PREF - - 1 2 - - NEXT >>>

1. DOS Batch - Simple Menu

Description

This simple menu framework parses itself for batch labels of certain signature and lists them as menu items. The self-parsing feature makes the menu generic. New menu items can be inserted by adding new function blocks without changing the menu infrastructure.

Features:

Script Output

 DOS Script Ouput
= Menu =================================================

  1  Have some fun
  2  Get a water

  T  Tip
  C  Clear Screen

Make a choice or hit ENTER to quit:
Download: BatchMenu.bat  

Script

  1. @ECHO OFF
  2. REM.-- Prepare the Command Processor
  3. SETLOCAL ENABLEEXTENSIONS
  4. SETLOCAL ENABLEDELAYEDEXPANSION
  5. :menuLOOP
  6. echo.
  7. echo.= Menu =================================================
  8. echo.
  9. for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo.  %%B  %%C
  10. set choice=
  11. echo.&set /p choice=Make a choice or hit ENTER to quit: ||GOTO:EOF
  12. echo.&call:menu_%choice%
  13. GOTO:menuLOOP
  14. ::-----------------------------------------------------------
  15. :: menu functions follow below here
  16. ::-----------------------------------------------------------
  17. :menu_1   Have some fun
  18. echo.Have some fun by adding some more code right here
  19. GOTO:EOF
  20. :menu_2   Get a water
  21. echo.Get a water and then add some code right here
  22. GOTO:EOF
  23. :menu_
  24. :menu_T   Tip
  25. echo.It's easy to add a line separator using one or more fake labels
  26. GOTO:EOF
  27. :menu_C   Clear Screen
  28. cls
  29. GOTO:EOF