Create Options or Choices in a Batch File
Are you really good at programming Batch Files, but you just don't know how to make those yes or no Choices or Menus that list Choices 1, 2, and 3? Well you've come to the correct place!
Contents
Steps
- Click Start>Run
- Type "cmd" (no quotations)
- Type "edit"
- Type the following, careless of bolded/unbolded worlds. After each press enter. Anything in parenthesis do NOT type, these are side-notes that tries to explain the steps.
- @echo off (This command will 'hide' the command input - optional but recommended)
- cls (This will clear anything above - optional but recommended if you're wanting to make it look neat)
- :start
- echo.
- echo Choice 1 ("Choice 1" can be renamed to whatever you want, any of the choices)
- echo Choice 2
- echo Choice 3 (Keep doing that until you have all of the choices that you need.)
- Type "set /p choice=(Insert question or command here, like "Yes or no?")
- if not '%choice%'== set choice=%choice:~0,1%
- if '%choice%'=='1' goto :choice1
- if '%choice%'=='2' goto :choice2
- (Continue doing this pattern until you have enough. Then type:)
- echo "%choice%" is not a valid option. Please try again.
- echo.
- goto start
- After that you type:
- :choice1
- (commands you want to run)
- goto end
- :choice2
- (commands)
- goto end
- :choice3
- (commands)
- goto end
- Continue doing this pattern until you have completed the file.
- :end
- pause
- exit
- Save this as a .bat file. Double click to test your batch file.
Example
Tips
- Type choice /? in the Command Prompt for more info.
- Type /help in the Command Prompt for more info.
- You can rename :choice1 or any others to whatever you like, as long as you keep it the same throughout the entire file.
- Edit command in command prompt does not work in Windows 8. This command is available for windows XP/Vista/Windows 7.
Warnings
- Command that are used without knowledge may harm your computer.
- Do not use commands unless you know what you are doing.
Related Articles
- Create a Relational Data Model
- Become a Programmer
- Learn a Programming Language
- Hand Trace Through Software Code