There are three executable files in DOS, respectively exe,com and bat (the current page supports the cmd extension). Among them, exe and COM file are binary form, only bat file is text form, can read directly. As a result, the bat file is much simpler than the binary executable file. These files contain a collection of DOS commands, usually called batch files.
Although the composition of batch files is relatively simple, but its use is very large, and more widely used. For example, every time you execute some of the same commands, you will be in a lot of trouble, but it's much easier to do it in a batch file. AUTOEXEC. BAT is a special batch file, which runs automatically when DOS is started, and plays a very important role in the configuration of the system. Therefore, to learn DOS, we must learn batch processing documents. The following describes the commands for batch files and their use.
DOS self-brought batch command:
@: Put this symbol in front of the other commands in the batch file, the runtime will not display the command itself.
If the @echo off command is often used in the first batch of files.
Call: Invokes another batch file from one batch file, and continues executing the original batch file after the call is completed.
Usage: call [batch filename]
Note: You can also use the COMMAND/C command to complete the same operation.
CHOICE: Select command. This is a DOS external command, but it is mainly used in batch files.
When the choice command is executed, it prompts for a selectable item, which is selected by a key.
Usage: choice:[/c[:] key sheet] [/n] [/S] [/t[:] Select value, seconds] [show text]
Where the/C indicates an optional key,/n means not to display the prompt,/s for uppercase and lowercase character sensitivity,/t means that a selected value defined in/C is automatically executed if there is no selection within the time of the approval. The display text is the prompt message when the choice command executes. The selection results are represented by ERRORLEVEL values.
ECHO: Displays the specified information. Usually appears on the screen.
such as echo hello will display the word hello on the screen.
In addition, ECHO on| Off is used to set whether the command itself is displayed when a batch file is executed. echo off is the same as @, but it is a separate command and cannot be placed before other commands like @.
For: Runs the appropriate command for the specified file.
As you know, many commands in DOS support wildcard characters, such as? and *, you can specify a batch of files at a time, very convenient. However, not all DOS commands support wildcard characters, such as type (the file content Display command) is not supported. It's okay to have a for command, which makes it possible for the type command to display multiple files at once.
Usage: for% variable name in (file set) do command [command arguments]
Note: The above is a fixed form for the for command, the in and do positions must be correct, or a syntax error will be prompted.
such as the For%F in (*.*) do type%F command enables the type command to display multiple files at a time.
Note:%f is a variable name, can also be replaced with%g, but must be consistent. Replace with%%f in the batch file.
Goto: Go to a label within a batch file to execute.
As you know, in programming, you often need to repeat or jump to a place to continue, such as the Goto command in basic language. The goto command in the batch file can also perform similar functions.
Usage: GOTO [Label name]
Among them, the label name can be set arbitrarily, such as Hello. Set the label with the ":" Symbol, such as ": Hello", when the goto Hello command will go to ": Hello" where the batch file continues to execute.
IF: Conditional judgment command. This is a very useful batch command.
Usage 1:if [NOT] EXIST filename command [command parameters]
Meaning: If a file is not present it will execute a command.
Usage 2:if [NOT] ERRORLEVEL error return code command [command parameters]
Meaning: If the error returns a code [not] greater than or equal to the specified code name, a command is executed.
Among them, ERRORLEVEL represents the error return code, very useful. For many DOS commands, these commands return different code names to represent different results, depending on the results of the execution (such as execution success, execution failure, or interruption by the user). The IF ERRORLEVEL command performs different commands on different codes that are based on this different result, usually after a command. if errorlevel 1 ECHO ok! indicates that "ok!" is displayed on the screen if the current error returns a code greater than or equal to 1 o'clock The words.
Usage 3:if [NOT] string 1== string 2 command [command arguments]
Meaning: Executes a command when string 1 and string 2[are not equal.
PAUSE: Suspends execution of batch files and displays the words "Press any key to continue".
REM: adding annotations. Used to increase file readability and will not be executed. You can also use:: To replace.
DOS command
Dos
DOS is to execute the program by entering the English command plus the ENTER key, which DOS is called a single task operating system.
Files with a suffix of exe, COM, or bat can be executed directly. These exe-suffix files are called executable files, files with COM suffixes are called command files, and bat-suffix files are called batch files. If we want to execute these files, simply type the file base name at the prompt and then enter, without the need for a file suffix.
The so-called batch processing, is to be able to execute a lot of commands, when we want the computer to complete a series of tasks, can be a single command of the execution, you can put these commands into a file, as long as a knock on the file name, the computer will be a batch of orders executed at once.
In DOS, there is a concept of the current directory, which is the directory displayed by the prompt, now the prompt is C:\, then the current directory is the root of the C disk, which (backslash) represents the root directory.
When we enter the executable file name, DOS will look for the file in the current directory, and if it does not have the file, Dos prompts for the error message.
To fully express a subdirectory should be a disk alphanumeric directory, such as C: \dos\temp, so the complete presentation of the file? is the disk alphanumeric directory plus filename, such as C:\DOS\TEMP\ME. Txt,c:\dos\temp\ is called the ME.TXT path. Note: If there are spaces in the path, the entire path is surrounded by "path" double quotes.
As we said earlier, when you enter an executable file name, DOS will look for the file in the current directory, if not found, will prompt the wrong file name, but we do not have to change the current directory to the directory where the file can run it, you can add the full path before the file name, For example, our current directory is C:\DOS, we want to run D:\TEST\PCT. EXE, then we can enter D:\TEST\PCT directly. EXE carriage return so that we can execute files in other directories without changing the current directory.
Dos commands are divided into internal commands and external commands, and internal commands are loaded with Command.com, and the external command is a separate executable file.
Internal commands are concentrated in a Command.com file in the root directory, which is read into memory every time the computer is started, which means that when the computer is running, these internal commands reside in memory, and the internal commands are not visible with Dir. The external commands are stored in a separate file on the disk, they are the COM and exe-suffix files, they are not resident memory, only when the computer needs, will be transferred into memory.
What is the difference between a wildcard and a *? * Can replace more than one character in the filename, and? can only be substituted for a single character in the filename.
When using wildcards, the file base name and extension can have a maximum of one *, and multiple may occur without exceeding the file name and extension length.
1. # Time #显示当前时间
2. #dir #查看当前目录下的文件和目录信息
# dir/p #翻页显示
3. #mem #查看当前系统的内存情况
4. #cd #改变当前目录
Cd.. # in DOS, this two o'clock represents the upper-level directory of the current directory, a point representing the current directory
The CD \ #\ represents the root directory.
5. #盘符: #更换当前目录到硬盘的其它分区
6. # MD (make directory--create directory)
7.# Rd (remove directory--Delete directory)
8. #exit #退出dos终端
9. #copy source file name destination file name #复制
#del filename #删除当前目录的某个文件
One. #ren source file name destination file name #改文件名
#type filename #查看文件里的内容
#del *.* or Del. #删除当前目录中的所有文件
#format A: #格式化磁盘