If Goto choice for is a more advanced command in a batch file, you are an expert in batch files if you use them skillfully.
If the condition is judged to be in compliance with the stipulated conditions, it is decided to execute different commands. There are three different formats:
1, if "parameter" = = "string" command to be executed
If the parameter is equal to the specified string, the condition is set, the command is run, or the next sentence is run. (note is two equals)
If "%1" = = "A" format a:
2, if exist file name to execute command
If you have the specified file, the condition is set, run the command, or run the next sentence. such as if exist Config.sys edit Config.sys
3, if errorlevel the number of orders to be executed
If the return code equals the specified number, the condition is set, the command is run, or the next sentence is run. If the IF errorlevel 2 goto x2 DOS program runs, it will return a number to DOS, called the error code ERRORLEVEL or return code.
The goto batch file runs here and jumps to the label specified by Goto, and is generally used in conjunction with IF. Such as:
Goto END
: End
The echo this are the end
Label used: string indicating that the line of the label is not executed
Choice Use this command to allow the user to enter a character to run different commands. Use should be added/C: parameter, the letter should be written after the prompt can enter characters, no spaces between. Its return code is 1234 ...
such as: Choice/c:dme defrag,mem,end
will display
Defrag,mem,end[d,m,e]?
For example, the contents of Test.bat are as follows:
@echo off
Choice/c:dme Defrag,mem,end
if errorlevel 3 goto defrag should first determine the highest number of error codes
if errorlevel 2 goto MEM
If Errotlevel 1 goto end
:d Efrag
C:\dos\defrag
Goto END
: Mem
Mem
Goto END
: End
echo Good bye
When this file is run, will display defrag,mem,end[d,m,e]? The user may select D m e, and then the IF statement will make a judgment, d means the execution label is defrag the program segment, m means the execution marking is the program segment of Mem, E represents the execution label as end of the program segment, each program paragraph ends with Goto ended the program jumps to the final label place, The program then displays the good bye and ends the file.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.