The content of the batch file is: file representation:
Echo off does not display the command line
Dir c: /*.*> a.txt writes the C disk file list to A.txt
Call C: /ucdos/ucdos.bat call UCDOS
echo Hello, "Hello"
Pause pause, wait for the button to continue
REM uses WPS annotations to use WPS
CD UCDOS enters UCDOS directory
WPS uses WPS
If Goto Choice for is a relatively advanced command in a batch file. If you are very skilled, you are an expert in batch files.
The if indicates whether it is determined whether or not the specified condition is determined to determine the execution of different commands. There are three formats: 1, if "==" String "The command parameter to be executed is equal to the specified string, the condition is established, run the command, otherwise run the next sentence. (Note is two equal numbers) such as if "% 1" == "a" format A:
2, if the command to be executed, if there is a specified file, the condition is established, run the command, otherwise run the next sentence. If exist config.sys edit config.sys
3, if the command to be executed if the command to be executed If the return code is equal to the specified number, the condition is established, run the command, otherwise run the next sentence. If the IF Errorlevel 2 Goto X2 DOS program is running, a number is returned to DOS, called an error code Errorlevel or a return code.
Goto batch file runs here will jump to the reference numeral specified by Goto, generally used with the IF. Such as:
Goto end
: End echo this is the end
Number use: string representation, the label is not executed
Choice Use this command to allow users to enter a character to run different commands. When using, you should add / c: parameters, C: After you should write the prompt that the characters can be entered, there is no space. Its return code is 1234 ...
Such as: Choice / C: DME DEFRAG, MEM, END will display DEFRAG, MEM, END [D, M, E]?
For example, Test.bat is as follows: @echo off choice / c: DME Defrag, MEM, END IF Errorlevel 3 Goto Defrag should first judge the highest value of error code if Errorlevel 2 Goto Mem if Errotlevel 1 Goto End
: Defrag C: / DOS / Defrag Goto End
: Mem Mem Goto End
: End echo good bye
After this file runs, the DEFRAG, MEM, END [D, M, E]? The user can select DME, then the IF statement will make a judgment, and D represents the block segment executing the label DEFRAG, and M represents the program that is labeled MEM. Segment, e represents a block that executes the label End, and each block is finally jumped to the END Number with Goto End, and then the program will display good Bye and the file ends.
The for loop command, as long as the condition meets, it will execute the same command multiple times.
Format for [%% F] in (Collection) DO [Command] As long as the parameter f is within the specified collection, the condition is established, execute the command
If there is a line in a batch file: for %% C in (* .bat * .txt) Do Type %% C meaning is if it is the file ending with BAT or TXT, the contents of the file are displayed. DOS will automatically run the autoexec.bat in the startup, usually we load each required program, such as: Path, SmartDRV (Disk Acceleration), Mouse (Mouse Start), MSCDEX, Doskey (Keyboard Management), Set (Set Environment Variable), etc..
If this file does not have this file in the root directory, the computer will allow the user to enter the date and time.
For example, a typical autoexec.bat content is as follows:
@echo off does not display the command line
Prompt $ P $ g Set a directory prompt before prompt
PATH C: / DOS; C: /; C: / Windows; C: / Ucdos; C: / Tools Settings Path
LH C: /DOS/doskey.com Load Keyboard Management
LH c: / mouse/mouse.com loading mouse management
LH C: /DOS/smartdrv.exe loading disk accelerated management
LH C: / DOS / MSCDEX / S / D: MSCD000 / M: 12 / V Loading CD-ROM Drive
Set Temp = C: / TEMP Settings Temporary Directory
% Indicates the parameters, the parameter refers to the string after the file name after running the batch file. Variables can represent file names from% 0 to% 9,% 0, and character strings are represented by% 1 to% 9.
For example, the C: root directory next batch file name is f.bat, content is format% 1
If you do C: /> f A:, it actually executes Format A:
Another example is the name of a batch of processing files in the root directory, the content is type% 1 TYPE% 2
So running C: /> t a.txt b.txt will display the contents of A.TXT and B.TXT files sequentially