Use the batch file - the meaning of batch file

xiaoxiao2021-03-06  99

The suffix is ​​the BAT file is a batch file, a text file. Simply put, its role is that automatic continuous execution multiple commands, the content of the batch file is a command. What is it used?

For example, when starting the WPS software, you must execute each time.

C: /> CD WPS C: / WPS> SPDOS C: / WPS> PY C: / WPS> WBX C: / WPS> WPS

If you execute it every time you use WPS, do you feel very trouble?

If there is a method, just write a batch file, you will automate all of the commands, do you want to learn?

When you finish this section, you will be shocked when you write the first batch file.

In addition, the computer will find this batch file per time, so that some commands to be executed each time, such as setting the path PATH, load the mouse drive Mouse, disk acceleration SmartDRV, etc., you can make your computer Really automated.

Echo, @, call, pause, REM is the most common command of the batch file, we start learning from them.

Echo indicates that the character echo off after this command indicates that all run commands after this statement does not display the command line itself @ and the echo offline, but it is the front of the other command line, indicating that the runtime is not displayed The line itself. CALL calls another batch file (if you call other batch files directly, the current file will not be executed after that file will not be able to execute the current file) PAUSE run this sentence will be paused, showing the press any key to continue ... Waiting for the user to press any After the key, continue REM indicates that the characters after this command are explained, not executed, just find it in the future.

Example: Edit a.bat file with Edit, enter the following contents After the store is c: /a.bat, you can implement it after executing the batch file: write all the files in the root directory to a.txt, start UCDOS, enter WPS Waiting for functions.

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

Batch files can also be used as a parameter like a C language, which requires only one parameter representation%.

% 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

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 if exist config.sys edit config.sys 3, if ErrorLevel Digital Sworthy command 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 will return to DOS, called error code Errorlevel or the return code GOTO batch file runs here will jump to the reference numeral specified by Goto, generally in conjunction with IF. Such as: goto end: endecho this is the end Number use: String Representation, the row in the label is not executed with this command allows the user 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 offchoice / C: DME DEFRAG, MEM, Endif Errorlevel 3 Goto Defrag First Judgment The highest error code IF ErrorLevel 2 Goto Memif Errotlevel 1 goto end: defragc: / dos / defraggoto end: memmemmemgoto end: endecho good by this file, 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 a block that executes the label MEM, and E indicates that the label is END. The block, each block finally jumps to the END Number with goto End, and then the program will display good bye, 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, and the command is executed if there is a line in a batch file: for %% c in (* .bat *. TXT) DO TYPE %% C meaning is if it is a file ending with BAT or TXT, the contents of the file are displayed. Autoexec.bat

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 Load 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

转载请注明原文地址:https://www.9cbs.com/read-123768.html

New Post(0)