Windows Batch Syntax

Source: Internet
Author: User
Tags echo command file copy goto switch case alphanumeric characters

Windows Batch Basics
Files that have the extension bat (which can also be cmd under nt/2000/xp/2003) are batch files.

* = = =======================================
. BAT is a DOS batch file
. cmd is another batch file for the NT Kernel command-line environment
From a broader perspective, Unix shell scripts and other operating systems, and even text that is interpreted by shells in the application, have the same effect as batch files, and are also interpreted by a dedicated interpreter in a behavioral unit, which is a more general form of scripting language. So from a certain level of analysis, batch, Unix shell, awk, Basic, Perl and other scripting languages are the same, but the scope of application and interpretation of the platform are different. Even some applications still use the term batch, whose content and extension are completely different from DOS batches.
===================================

The first batch file is a text file, each line of this file is a DOS command (most of the time as we do at the DOS prompt command line), you can use the DOS edit or Windows Notepad (Notepad) Wait for any text file editing tool to create and modify batch files.

* = = ===================
Non-DOS commands can be used entirely in batch files, and even ordinary data files that do not have executable characteristics can be used, due to the involvement of the new interpretation platform of Windows systems, which makes batching applications increasingly "marginalized". Therefore, we discuss the batch processing should be confined to DOS environment or command-line environment, otherwise many concepts and settings need to make a relatively large change.
========================

Second, a batch file is a simple program that can control the flow of command runs through conditional statements (if) and Process Control statements (GOTO), and you can use circular statements (for) to loop through a command in a batch. Of course, the programming ability of batch file is very limited and very nonstandard compared with programming statements such as C language. Batch program statements are all DOS commands (including internal commands and external commands), and the ability to batch processing depends largely on the commands you use.

* = = ==================
A batch file can also be called a batch program, which differs from a compiled language in that a file with a C or CPP extension can be called a C language file or C source code, but only after the connection is compiled. EXE file can be called a C language program. Because the batch file itself has both the readability of the text and the enforceability of the program, the boundaries of these titles are rather vague.
===========================

Thirdly, each well-written batch file is equivalent to a DOS external command, and you can put its directory in your DOS search path (path) so that it can run anywhere. A good habit is to build a bat or batch directory on your hard disk (for example, C:\BATCH), and then put all the batch files you write into that directory so that you can run all the batch programs you write in any location as long as you set up c:\batch in path.

* = = =====
Pure DOS system, executable program can be subdivided into five categories, according to the execution priority from high to low arrangement is: Doskey macro command (pre-resident memory), command. Internal commands in COM (memory-based environments at any time), executable programs with COM extensions (loaded directly into memory by Command.com), executable programs with EXE-bit extensions (loaded into memory by Command.com), A batch program with the bat-bit extension (interpreted by Command.com, which invokes the 2,3,4,5 executable program in order of priority based on its content, parses a row, executes a row, and the file itself does not load memory)
============ IV, under DOS and win9x/me systems, C: The Autoexec.bat batch file under the packing directory is the batch file that runs automatically every time the system starts, you can put the command that will run every time the system starts, such as setting the search path, adjusting the mouse driver and disk cache, setting the system environment variables, and so on. The following is an example of a Autoexec.bat running under Windows 98:
@ECHO OFF
PATH C:\WINDOWS; C:\WINDOWS\COMMAND; C:\UCDOS; C:\dostools;<br>
C:\SYSTOOLS; C:\WINTOOLS; C:\BATCH
LH smartdrv. exe/x
LH Doskey.com/insert
LH Ctmouse. Exe
SET temp=d:\temp
SET tmp=d:\temp
* = = =====
AUTOEXEC. BAT is the automatic running batch file of DOS system, which is interpreted and executed by Command.com when it is started;
And in the Win9x environment, not only increased support for Dosstart. BAT, Winstart. Many other auto-running batch files, such as BAT, have also been added to Autoexec.bat. Dos. W40. Bak. Old. PWS and many other variants to adapt to complex environments and changing needs.
= = = = Willsort Compilation Note =============
There are a lot of things to be worth thinking about in the following categories of orders. The "@" command is not a command, and commands such as Dir, copy and so on are not included, and all commands in the Special command are common commands for me. It is recommended that the commands referenced by the batch be divided into internal commands, external commands, third-party programs, and three other categories. In the internal and external commands, there is a class of commands that are dedicated to or used in batches, which can be called batch commands.

The following excerpt from the MS-DOS 6.22 help document about "batch commands", of course, some of these concepts and definitions are somewhat behind.

Batch processing command

A batch file or batch program is a body file that contains several MS-DOS commands with the extension. BAT. When you are typing the name of a batch program at a command prompt, MS-DOS performs the commands in this batch program.

Any commands that can be used at the command prompt are available in the batch program. Additionally, the following MS-DOS commands are specifically used in a batch program.
==========

Common commands

Echo, @, call, pause, REM (tip: Use:: Instead of REM) are some of the most common commands for batch files, and we start with them.

* = = ===========
First, @ is not a command, but rather a special token for the DOS batch, only for masking command-line echo. Here are some special tokens that you might see in a DOS command line or batch:
CR (0D) command line terminator
Escape (1B) ANSI escape character guide
Space (20) commonly used parameter specifiers
Tab (09); = Non-commonly used parameter qualifiers
+ Copy command file connector
* ? File wildcard characters
"" String delimiter
| Command pipe character
< > >> file redirection
@ command-line Echo mask
/Parameter Switch guide
: Batch Label Guide
% Batch Variable guide

Second,:: indeed can play the role of REM annotation, and more concise and effective; But there are two points to note:
First, in addition to: outside, any of the following: The beginning of the word lines, in the batch is regarded as the label, and directly ignore all the contents thereafter, just to distinguish from the normal marking, we recommend using Goto is not recognized by the label, that is, immediately after a non-alphanumeric special symbol.
Second, unlike REM, the following character lines is not echoed at execution time, regardless of whether the command-line echo is turned on with Echo on, because the command interpreter does not consider him to be a valid command line, and for this point, REM will be more applicable in some cases than:: In addition, REM can be used in Config.sys files.
=====================

Echo indicates the character that appears after this command
echo off means that all running commands do not display the command line itself after this statement
@ with echo off, but it is added at the front of each command line, indicating that the runtime does not display this line of command line (only affects the current row).
Call calls another batch file (if the batch file is called directly without calling, the current file cannot be returned and subsequent commands for the current file are executed after the batch file is executed).
Pause running this sentence pauses the execution of the batch and displays the press any key to continue on the screen ... Prompt, waiting for the user to press any key to continue
REM indicates that the word identifier after this command is interpreted as a line (note), not executed, but for future reference (equivalent to comments in the program).
* = = =====
The description here is confusing, rather than a command line that refers directly to a command to help a more organized

-------------------------
ECHO

Displays or hides the body of the batch program when the program is running. can also be used to allow or suppress the echoing of commands.

When you run a batch program, MS-DOS typically displays (echoes) commands in the batch program on the screen.
Use the echo command to turn this feature off.

Grammar

ECHO [on| OFF]

To display a command with the echo command, you can use the following syntax:

echo [Message]

Parameters

on| OFF
Specifies whether to allow echo of the command. To display the current echo settings, you can use the echo with no parameters
Command.

Message
Specifies the body to let MS-dos display on the screen.

-------------------

Pager

Calls another batch program from one batch program without causing the abort of the first batch process.

Grammar

Call [Drive:][path]filename [Batch-parameters]

Parameters

[Drive:] [Path]filename
Specifies the name of the batch program to invoke and where it is stored. The file name must be used. Bat as the extension.


Batch-parameters
Specifies the command line information required by the batch program.

-------------------------------

PAUSE

Pauses execution of the batch program and displays a message prompting the user to press any key to continue execution. Only at the batch place
This command is used in the manager program.

Grammar

PAUSE


Rem

Add annotations to a batch file or Config.sys. You can also use the REM command to block commands (in Config.sys
can also be used in semicolons; Instead of the REM command, it cannot be overridden in a batch file.

Grammar

REM [string]

Parameters

String
Specifies the command to block or the annotations to include.
=======================

Example 1: Edit the A.bat file with edit, enter the following to save to C:\a.bat, after executing the batch file can be implemented: the root directory of all files written to A.txt, start Ucdos, into WPS and other functions.

The contents of the batch file are: command comments:

@echo off does not display subsequent command lines and the current command line
Dir c:\*.* >a.txt writes the C-drive file list A.txt
Call C:\ucdos\ucdos.bat calls Ucdos
echo Hello show "Hello"
Pause paused, wait for key to continue
REM Ready to run WPS Note: Ready to run WPS
CD Ucdos into the Ucdos directory
WPS running WPS

Parameters for batch Files

A batch file can also use parameters (equivalent to command-line arguments of a DOS command) in the same way as a C-language function, which requires a parameter representation of "%".

%[1-9] Represents a parameter, which is a string separated by a space (or tab) after the file name when the batch file is run. Variables can represent the batch command itself from%0 to%9,%0, and the other parameter strings are represented in the%1 to%9 order.

Example 2:C: The root directory has a batch of processing files named F.bat, the content is:
@echo off
Format%1

If you do c:\>f a:
Then when the F.bat is executed,%1 represents a:, so that the format%1 is equivalent to format a: So the above command actually executes the format a when it is run:

Example 3: C: Root directory The next batch of processing file name is T.bat, content is:
@echo off
Type%1
Type%2

Then run c:\>t a.txt b.txt
%1: Represents a.txt
%2: Represents b.txt
The above command then displays the contents of the A.txt and B.txt files sequentially.

* = = ===============
Parameters are also treated as variables in a batch, so use the percent sign as the guide, followed by a number in 0-9 to form the parameter reference. The relationship between the reference character and the argument (for example,%1 and a: above) is similar to the relationship of the variable pointer to the variable value. When we want to refer to the 11th or more parameters, we must move the DOS parameter start pointer. The shift command is acting as the move pointer, which moves the starting pointer of the parameter to the next parameter, similar to the pointer operation in C. This is illustrated below:

Initial state, CMD is the command name, you can use%0 Reference
CMD arg1 arg2 arg3 arg4 arg5 arg6 arg7 Arg8 arg9 arg10
^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | | |
%0%1%2%3%4%5%6%7%8%9

After 1 times shift, CMD cannot be referenced
CMD arg1 arg2 arg3 arg4 arg5 arg6 arg7 Arg8 arg9 arg10
^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | | |
%0%1%2%3%4%5%6%7%8%9

After 2 shift, arg1 is discarded,%9 points to null, no referential meaning
CMD arg1 arg2 arg3 arg4 arg5 arg6 arg7 Arg8 arg9 arg10
^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | | |
%0%1%2%3%4%5%6%7%8

Unfortunately, the inverse of shift is not supported under Win9x and DOS. Shift supports the/n parameter only in the NT kernel command-line environment, and you can move the start pointer with the first parameter as the base.
=================

Special commands


If Goto choice for is a more advanced command in a batch file, you are the expert on batch files if you use them skillfully.


If is a conditional statement used to determine whether the conditions are met, thus deciding to execute different commands. There are three types of formats:

1, if [not] "parameter" = = "string" command to execute

If the parameter equals (not equal to, the same as) the specified string, the condition is set, run the command, or run the next sentence.

Example: If "%1" = = "A" format a:

====

The description of this point in the IF command-line help is:
IF [NOT] string1==string2 command
Here are some points to note:
1. Double quotation marks that contain strings are not required by syntax, but are used only as an "anti-aircraft" character
2. String1 is not necessarily a parameter, it can also be an environment variable, a loop variable, and other string constants or variables
3. command is not required by syntax, string2 followed by a space to form a valid command line
=============================

2. If [not] exist [path \] filename to execute command
If there is a specified file, then the condition is established, run the command, otherwise run the next sentence.

Such as: if exist C:\Config.sys type C:\Config.sys
Indicates that if a C:\Config.sys file exists, its contents are displayed.

Note ********
You can also use the following usage:
If exist command
Device refers to devices that have been loaded in a DOS system, usually under Win98:
AUX, PRN, CON, NUL
COM1, COM2, COM3, COM4
LPT1, LPT2, LPT3, LPT4
XMSXXXX0, EMMXXXX0
A:B: C: ...,
clock$, config$, dblbuff$, ifs$hlp$
The specific content will vary slightly depending on the hard software environment, and the following three points need to be guaranteed when using these device names:
1. The device does exist (except for devices that are virtual by the software)
2. The device driver is loaded (AUX, PRN and other standard devices are defined by the system default)
3. The device is ready (mainly refers to a:b: ..., com1 ..., lpt1 ... such as
Available by Command Mem/d | Find "Device"/I to review the devices that are loaded in your system
In addition, in a DOS system, the device is also considered a special file, and the file can also be called a character device; Because the device and the file are managed using a handle (handle), the handle is the name, similar to the file name, except that the handle is not applied to disk management, but is applied to memory management, and so-called device loading refers to allocating a reference handle to it in memory.
==================================

3. If errorlevel < digital > Pending command

Many DOS programs return a numeric value at the end of the run to indicate the result (or state) of the program's operation, and the IF ERRORLEVEL command can determine the return value of the program, depending on the return value, to execute different commands (the return value must be in the order of magnitude to small). If the return value equals the specified number, the condition is set up, run the command, or run the next sentence.

if errorlevel 2 goto x2

* = = ===========
The return values from large to small are not required, but are only used when the command is Goto, and when set is used as the execution command, it is usually ordered from small to large, such as the need to place the return code in the environment variable, using the following sequence form:

if errorlevel 1 set el=1
if errorlevel 2 set el=2
if errorlevel 3 set el=3
if errorlevel 4 set el=4
if errorlevel 5 set el=5
...

Of course, you can also use the following loops to replace the principle is consistent:
For%%e in (1 2 3 4 5 6 7 8 ...) do if errorlevel%%e set el=%%e

More efficient and concise usage, you can refer to another article I wrote about getting errorlevel.

The reason for this phenomenon is that if the ERRORLEVEL comparison return code judgment condition is not equal to, but greater than equals. Since the goto feature, from small to large sort will cause the small return code at the jump; Because of the "duplicate" assignment of the set command, the large-to-small sort results in a smaller return code that "overwrites" the larger return code.

Also, although the If errorlevel=< number > command is also valid, it is only command.com to interpret the command line and ignore it as a command row separator
===========================


The goto batch file runs here will jump to the label specified by Goto (label is label, labeled with: followed by a standard string to define), goto statement is generally used with if, according to different conditions to execute different command groups.

Such as:

Goto END

: End
Echo This is the end

The label is defined with a ": string" and the line of the label is not executed.

= = = Willsort Compilation Note

Labels are often translated as "tags", but this is not broadly agreed.

Goto and: Can be implemented in conjunction with the jump, and then the if can implement the conditions of the branch, multiple if can implement the grouping of commands, similar to the C switch case structure or the Select Case structure in Basic, large-scale and structured command grouping function functions in a high-level language can be implemented. The following is a comparison of the syntax structure of batches and C/basic:

Batch C/basic
Goto&: Goto&:
Goto&:&if if{}&else{}/If&elseif&endif
Goto&:&if. Switch&case/select case
Goto&:&if&set&envar ... function ()/function (), sub ()
==================================
Choice Use this command to allow the user to enter a character (for selection), to return different ERRORLEVEL based on the user's choice, and then to run the different commands according to the user's choice, if errorlevel mates.

Note: The choice command is a DOS or Windows system-provided external command, different versions of the choice command syntax will be slightly different, please use the choice/? View usage.

Choice command syntax (this syntax is the syntax for the Choice command in Windows 2003, and the command syntax for other versions of choice is similar):

CHOICE [/C choices] [/n] [/cs] [/T timeout/d CHOICE] [/M text]

Describe:
This tool allows the user to select an item from the selection list and return the index of the selected item.

Parameter list:
/C choices Specifies the list of options to be created. The default list is "YN".

/n Hides the list of options in the prompt. Prompts the previous message to be displayed,
option is still enabled.

/cs allows selection of case-sensitive options. By default, this tool
is not case-sensitive.

/T Timeout The number of seconds to pause before making a default selection. Acceptable values are from 0
to 9999. If 0 is specified, there is no pause, and the default option
will be chosen.

/d Choice Specify the default options after nnnn seconds. Characters must be selected with/C
A set of choices specified by the item; At the same time, nnnn must be specified with/T.

/M text Specifies the message to display before prompting. If not specified, the tool only
Displays the prompt.

/? Displays the help message.

Attention:
The ERRORLEVEL environment variable is set to the key index selected from the selection set. The first selection listed
Returns 1, the second option returns 2, and so on. If the user presses a key that is not a valid selection,
The tool will issue a warning noise. If the tool detects an error state, it returns 255 of the
The ERRORLEVEL value. If the user presses the Ctrl+break or CTRL + C key, the tool returns 0
The ERRORLEVEL value. When using the ERRORLEVEL parameter in a batch program, the parameters are dropped
Sequential arrangement.

Example:
CHOICE/?
CHOICE/C ync/m "Confirm please press Y, no press N, or cancel please press C. "
choice/t 10/c ync/cs/d y
choice/c ab/m "option 1 Please select a, option 2 please select B. "
CHOICE/C ab/n/M "option 1 Please select a, option 2 please select B. "

= = = = Willsort Compilation Note ===============================
I listed win98 under Choice's usage help, has been funded to differentiate

Waits for the user to choose one of a set of choices.
Waits for the user to select one of a set of characters to be selected

CHOICE [/c[:]choices] [/n] [/S] [/t[:]c,nn] [text]

/c[:]choices specifies allowable keys. Default is YN
Specify the allowed keys (characters to be selected), default to Yn
/n Do not display choices and? At end of prompt string.
Do not display question marks and pending characters in the prompt string
/S Treat Choice keys as case sensitive.
Case sensitive when processing characters to be selected
/t[:]c,nn Default choice to C after nn seconds
C is selected by default after nn seconds
Text Prompt string to display
The prompt string to display
ERRORLEVEL is set to offset by key user presses in choices.
ERRORLEVEL is set to the offset value of characters typed by the user in the character to be selected
If I run the command: choice/c ync/m "confirm Press Y, no press N, or cancel please press C. "
The screen will show:
Confirm Press Y, no press N, or cancel please press C. [Y,n,c]?


Example: The contents of Test.bat are as follows (note that when you use if errorlevel to determine the return value, you want to sort by the return value from highest to lowest):
@echo off
CHOICE/C dme/m "Defrag,mem,end"
if errorlevel 3 goto end
if errorlevel 2 goto MEM
if errorlevel 1 goto defrag

:d Efrag
C:\dos\defrag
Goto END

: Mem
Mem
Goto END

: End
echo Good bye

After this batch runs, "Defrag,mem,end[d,m,e" will be displayed, the user can select D M E, and if statement according to the user's choice to make a judgment, D for the execution of the program segment labeled Defrag, M for the execution of the program labeled MEM, E represents the execution of a program segment labeled End, where each segment ends with a goto end to jump the program to the end label, and then the program displays good bye, and the batch runs to the end.

The For loop command, which executes the same command multiple times, as long as the condition conforms.

Grammar:
Executes a specific command for each file in a set of files.

For%%variable in (set) do command [Command-parameters]

%%variable specifies a single-letter replaceable parameter.
(set) specifies one or a set of files. Wildcard characters can be used.
command specifies the commands to execute on each file.
Command-parameters
Specify parameters or command-line switches for specific commands.

For example, there is a single line in a batch file:
For%%c in (*.bat *.txt) do type%%c

The command line displays the contents of all files with the bat and txt extensions in the current directory.

= = = = Willsort Compilation Note =====================================================
It is important to note that when a string in () is not a single or multiple file names, it is simply replaced as a string, which, in addition to the () feature that can embed multiple strings, is clearly considered a traversal loop.
Of course, in the command-line environment of the NT/2000/XP/2003 series, for is given more features to parse the command output or the strings in the file, and many switches are used to extend the file substitution function.
========================================================================

Batch processing Example

1. If-exist

1) First Use Notepad to create a test1.bat batch file in C:, the file content is as follows.
@echo off
IF EXIST \autoexec. BAT TYPE \autoexec. BAT
IF not EXIST \autoexec. BAT ECHO \autoexec. BAT does not exist

Then run it:
C:\>test1. BAT

If C: \ has a Autoexec.bat file, its contents are displayed and if it does not exist, the batch will prompt you that the file does not exist.

2) Then create a Test2.bat file that reads as follows:
@ECHO OFF
IF EXIST \%1 TYPE \%1
IF not EXIST \%1 ECHO \%1 does not EXIST

Perform:
C:\>test2 AUTOEXEC. BAT
The command runs as shown above.

Description
(1) If EXIST is used to test whether a file exists, in the form of
IF EXIST [path + file name] Command
(2) The%1 in the Test2.bat file is a parameter, and DOS allows 9 batch parameter information to be passed to the batch file,%1~%9 (% 0 represents the Test2 command itself), which is somewhat like the relationship between the actual parameter and the formal parameter in the programming, and%1 is the formal parameter, AUTOEXEC. BAT is an argument.

= = = = Willsort Compilation Note =====================================================
DOS does not have the "Allow 9 batch parameter information" limit, the number of parameters is only limited by the command length and the processing power of the invoked command. However, we can only reference 10 parameters at the same time in a batch program, because DOS only gives the%0~%9 10 parameter references.
========================================================================

3) Further, create a file named Test3.bat, which reads as follows:
@echo off
IF "%1" = = "A" ECHO XIAO
IF "%2" = = "B" ECHO TIAN
IF "%3" = = "C" ECHO XIN

If you run:
C:\>test3 A B C
The screen will show:
XIAO
TIAN
XIN

If you run:
C:\>test3 A B
The screen will show
XIAO
TIAN

During the execution of this command, DOS assigns an empty string to the parameter,% 3.

2, If-errorlevel

Set up the Test4.bat, which reads as follows:
@ECHO OFF
XCOPY C:\AUTOEXEC. BAT D:\
IF ERRORLEVEL 1 ECHO file copy failed
IF ERRORLEVEL 0 ECHO Successful copy file

Then execute the file:
C:\>test4

If the file copy succeeds, the screen will display a "Copy file successfully" or the "copy of file failed" will be displayed.

IF ERRORLEVEL is used to test the return value of its previous DOS command, note that it is only the return value of the previous command, and the return value must be judged in order from large to small.
Therefore, the following batch file is incorrect:

@ECHO OFF
XCOPY C:\AUTOEXEC. BAT D:\
IF ERRORLEVEL 0 ECHO Successful copy file
IF ERRORLEVEL 1 ECHO not found copy file
IF ERRORLEVEL 2 ECHO user aborts copy operation via Ctrl-c
IF ERRORLEVEL 3 ECHO Preset error prevents file copy operation
IF ERRORLEVEL 4 Write error during ECHO copy

Whether the copy is successful or not, the following:

Copy file not found
User aborts copy operation via Ctrl-c
Preset error prevents file copy operation
Write error in copy process

are displayed.

Here are the return values of several commonly used commands and what they mean:

Backup
0 Backup succeeded
1 backup File not found
2 File Sharing violation prevents backup from completing
3 User aborted backup with Ctrl-c
4 The backup operation was aborted due to a fatal error

Diskcomp
0 disks are more identical
1 Disks Compare different
2 user aborted comparison operation via Ctrl-c
3 The comparison operation is aborted due to a fatal error
4 Preset Error Abort comparison

diskcopy
0 Disk copy operation succeeded
1 non-fatal disk read/write error
2 user end copy operation via Ctrl-c
3 The disk copy is aborted due to a fatal processing error
4 Preset error preventing copy operation

Format
0 formatting succeeded
3 user aborted format processing via CTRL-C
4 formatting aborted due to fatal processing error
5 at the prompt "Proceed with format (y/n)?" Under User type N end

Xcopy
0 successfully copied files
1 copy File not found
2 user aborted copy operation via Ctrl-c
4 Preset errors prevent file copy operations
5 Write Error during copy

Chkdsk
0 error not found
255 One or more errors were found

Choice
0 Users Press Ctrl+c/break
1 The user presses the first key
255 error conditions in the command line detected
The position of the valid characters pressed by other users in the list

Defrag
0 Fragment Compression succeeded
1 An internal error has occurred
2 There are no empty clusters on the disk. To run defrag, you must have at least one empty cluster
3 Users use CTRL + C to exit the defrag
4 General errors occur
5 Defrag encountered an error while reading a cluster
6 Defrag encountered an error while writing a cluster
7 Error allocating space
8 Memory Error
9 There is not enough space to compress disk fragmentation

deltree
0 successfully deleted a directory

Diskcomp
Same as 2 disks
1 Find different
2 Press CTRL + C to terminate the comparison
3 A critical error has occurred
4 initialization error occurred

Find
0 Lookup succeeded and at least one matching string was found
1 Search succeeded but no matching string was found
2 An error occurred in the lookup

keyb
0 Keyboard definition file loading succeeded
1 Use of illegal keyboard code, character set or syntax
2 keyboard definition file bad or not found
4 error during keyboard and monitor communication
5 The required character set is not ready

Move
0 successfully moved the specified file
1 An error has occurred

msav/n
86 checked to the virus.

Replace
0 replace succeeded in replacing or adding a file
1 MS-DOS version is incompatible with replace
2 Replace cannot find the source file
3 Replace cannot find the source path or destination path
5 cannot access the file to be replaced
8 Not enough memory to perform replace
11 Command-Line syntax error

Restore
0 Restore successfully restored the file
1 restore could not find the file to recover
3 Users Press CTRL + C to terminate the recovery process
4 Restore terminated because of an error

ScanDisk
0 ScanDisk does not detect any errors on the drive it checks
1 cannot run ScanDisk because the command line syntax is not correct
2 ScanDisk terminated unexpectedly due to memory exhaustion or an internal error
3 users get ScanDisk halfway out
4 user decides to exit early when disk scan is performed
254 ScanDisk found disk failure and corrected all
255 ScanDisk found disk failure, but failed to correct all

Setver
0 Setver successfully completed the task
1 user specified an invalid command switch
2 The user has specified an illegal file name
3 There is not enough system memory to run the command
4 user specified an illegal version number format
5 Setver The specified item was not found in the version table
6 setver SETVER.EXE File not found
7 user specified an illegal drive
8 User specified too many command-line arguments
9 setver detection of missing command line arguments
10 Setver detected an error while reading the SETVER.EXE file
One by one SETVER. EXE file corruption
12 The specified SETVER.EXE file does not support the version table
There is not enough space in the 13 version table to store the new item
14 Error Setver detected while writing SETVER.EXE file
========================================================================

3, IF STRING1 = = STRING2

Establish Test5.bat, the file contents are as follows:
@echo off
IF "%1" = = "A" FORMAT A:

Perform:
C:\>test5 A
The screen will appear with the contents of the A: disk formatted.

Note: In order to prevent arguments from being empty, it is common to enclose the string in double quotation marks (or other symbols, note that you cannot use a retention symbol).
such as: if [%1]==[a] or if%1*==a*

5. GOTO

Establish Test6.bat, the file contents are as follows:
@ECHO OFF
IF EXIST C:\AUTOEXEC. BAT GOTO _copy
GOTO _done
: _copy
COPY C:\AUTOEXEC. BAT D:\
: _done

Attention:
(1) The colon ":" of the ASCII character before the label, no space between the colon and the label.
(2) The naming rules for labels are the same as the naming rules for filenames.
(3) DOS supports a maximum of eight characters, and when two labels cannot be distinguished, jumps to the nearest label.

= = = = Willsort Compilation Note =====================================================
1) Labels are also known as tags (label)
2) tags cannot start with most non-alphanumeric characters, but can use many
3) When two labels cannot be distinguished, jumps to the top label of the position
========================================================================

6. For

Establish C:\TEST7. BAT, the file contents are as follows:
@ECHO OFF
For%%C in (*. BAT *. TXT *. SYS) do TYPE%%C

Run:
C:\>test7

After execution, the screen will display all the contents of the file (excluding hidden files) in the C: Packing directory with the name extension of bat, TXT, sys.

[Technorati Relative tag]

Article from Baidu Library

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.