Advanced Course on the command line selection of CMD, eds (rpm)

2010-11-06  来源:本站原创  分类:Tech  人气:232 

Chapter I Section I often batch based on the internal command batch Introduction
1, REM, and::
2, ECHO, and @
3, PAUSE
4, ERRORLEVEL
5, TITLE
6, COLOR
7, mode configuration system equipment
8, GOTO and:
9, FIND
10, START
11, assoc and ftype
12, pushd and popd
13, CALL
14, shift
15, IF
16, setlocal with variable delay (ENABLEDELAYEDEXPANSION / DISABLEDELAYEDEXPANSION
Enable or disable delayed environment variable extension. )
17, ATTRIB Displays or changes file attributes commonly used special symbols II
1, @ command line Shield character echo
2,% batch variables leading char
3,> redirection operator
4,>> redirection operator
5 ,<,>&,<& redirector
6, | command pipe character
7, the ^ escape character
8, & combination of command
9, & & combined orders
10, | | combination of command
11, "" string delimiter
12, comma
13; semicolon
14, () brackets
15! Exclamation point of a Chapter Detailed FOR command, the basic format of the second, the parameter / d directory only three parameters / R recursive (file name)
Fourth, the parameter / L range of values five iterations, the parameter / F Chapter iteration and parse the variable of a FOR command, ~ I - Remove any quotes ("), extended% I
Second,% ~ fI - the% I extended to a fully qualified path name three,% ~ dI - only% I extended to a drive letter d,% ~ pI - only% I extended to a path of five,% nI -% I only file name extension to a six-,% ~ xI -% I extend only to a file extension seven,% ~ sI - expanded path contains short names only eight,% ~ aI -% I will expand file attributes to the nine,% ~ tI - to% I extended to the file date / time ten,% ~ zI -% I will be extended to the size of the file XI,% ~ $ PATH: I
Chapter One batch of the variables, system variable b, since the set command to define variables Detailed chapter one, with the set command to set a custom variable Second, simple calculations with a three-set command, use the set command string processing
1, the string replacement
2, if the command string to explain the interception of Chapter VI of the first use: IF [NOT] ERRORLEVEL number command
The second use: IF [NOT] string1 == string2 command
The third use: IF [NOT] EXIST filename command
The fourth use: IF enhance the use of Chapter VII of the advanced techniques of a DOS programming, interface design two, if ... else ... the three conditional statements, loops IV, V subroutine, use ftp command to automatically download the sixth, with 7-ZIP to achieve compression and decompression command line seven, eight calls VBScript program, the executable file into nine batches, time delay
1, using ping command delay
2, using for the command delay
3, the use of vbs delay function, millisecond accuracy, error 1000 ms
4, only an arbitrary time delay of the batch command, precision of 10 ms, 50 ms error ten, eleven simulated progress bar, the special character of the input and application-second random number (% random%) of the application of skills XIII variable nested and nested command
1, corrected all the typos, proper layout, increase straight.
2, run all the examples to improve and correct some syntax errors.
3, added some incomplete areas.
4, the first chapter many tutorials online reference compiled.
5,20080229 add a variable delay.
6,20080305 modified description of the parameter usebackq
7,20080310 increased input and application of special characters
8,20080311 routine part of the revised
9,20080313 modified echo instructions, application methods are summarized 9
10,20080320 add arbitrary time delay method
11,20080321 increase set decimal and octal calculations confused description of the problem
12,20080325 amendment dos numerical range: -2147483648 to 2147483647, that is -2 ^ 31 to 2 ^ 31-1
13,20080326 increase the application of random numbers
14,20080327 modified "if increased usage" defined in the statement that
15,20080402 order to increase variable nested with nesting, one of the important skills.

================================================== ====================
Chapter batch used within a batch command based Introduction Section

Batch definition: the name suggests, is a series of batch file commands in sequence to a set of executable text file with the extension BAT or CMD. These commands are collectively referred to as batch commands.
Tips: You can press Ctrl + C keyboard key combination to forcibly terminate the execution of a batch process.
Understand the general meaning, we started learning. Look at a simple example!
@ Echo off
echo "Welcome to the very BAT!"
pause
The above three commands saved as a file and then run test.bat or test.cmd,
He will be on the screen displays the following two names:
Welcome to the very BAT!
Press any key to continue...
This is a simple batch file, this batch file will use a total of 2 commands "echo" and "pause" there is a special symbol "@"
This simple batch from the above, we can find that in fact some of the batch is to use symbols with special meaning to complete the assigned functions and some combination of the command, then the number in a batch of special symbols and functions that order? We will now take a closer look at some of the most popular!
(The following content source network, please read, good examples of the next section)
================================================== ====
Common command batch (not listed in order also more, please refer to help information)
1, REM, and::
2, ECHO, and @
3, PAUSE
4, ERRORLEVEL
5, TITLE
6, COLOR
7, mode configuration system equipment
8, GOTO and:
9, FIND
10, START
11, assoc and ftype
12, pushd and popd
13, CALL
14, shift
15, IF
16, setlocal with variable delay
17, ATTRIB Displays or changes file attributes introduces order
1, REM, and::
REM command to comment, generally used to add annotations to the program, the contents of the command is not executed, but it can echo.
Second,:: rem's comments can also play a role, but also simple and effective; but there are two points to note:
First, any colon: at the beginning of the character lines are considered in a batch label, and then ignore all the content directly.
Effective label: colon followed by a string of alphanumeric beginning, goto statements can be identified.
Invalid label: a colon followed by a special non-alphanumeric symbol, goto does not recognize the label, you can play the role of comments, so:: is often used as a comment character, in fact: + Note also play the role.
Second, the difference is rem,:: row after the implementation of the character does not echo, whether or not to open the command line with echo on echo state, because the shell does not think he is a valid command line, this point of view, rem, in some situations than:: more applicable; addition, rem can be used to config.sys file.

Inline comments format:%% footnotes (not commonly used, with caution)

2, ECHO, and @
@ Character on the command prior to the close the command echo, echo time regardless of whether the open.
The role of echo command are as follows:
(1) Open echo off Echo format: echo [{on | off}]
If you want to close the "ECHO OFF" command-line display of its own, you need to add the command line before the "@."
(2) shows the current status of ECHO to set the format: echo
(3) The output message format: ECHO ECHO command information content above is the three common usage, is familiar and will use, but as a DOS command gold digger you should know the following tips:
(4) Close the DOS command prompt in the DOS prompt, type ECHO OFF, close the DOS prompt to display the screen, leaving only the cursor, until the type ECHO ON, prompt will reappear.
(5) output blank line, which is equivalent to entering a carriage return format: ECHO.
It is noteworthy that the command line "." Back to keep the middle of the ECHO can not have spaces, or "." Message will be used as output to the screen. Another "." Can ,:;"/[ \] + and other symbols of any alternative.
Command ECHO. Enter the output, the DOS pipe turn can be used as input to other commands, such as echo. | Time which is equivalent to the TIME command is given after a carriage return. Therefore, the system will perform in shows the current time, automatically returns to the DOS prompt (6) answer questions in the format of the command: ECHO reply language | command file name of the format can be used to simplify the commands that require man-machine dialogue (such as : CHKDSK / F; FORMAT Drive:; del *.*) operation, it is through the DOS ECHO command pipe command to preset the output response as the man-machine dialogue language command input. The following example is equivalent to calling the command in the man-machine dialogue appears, enter "Y" Enter:
C:> ECHO Y | CHKDSK / F
C:> ECHO Y | DEL A: *.*
(7) Create a new document format, or increase the contents of the file: ECHO contents of the file> File Name
ECHO file content>> file name for example:
C:> ECHO @ ECHO OFF> AUTOEXEC.BAT batch file to automatically create
C:> ECHO C: \ CPAV \ BOOTSAFE>> AUTOEXEC.BAT file to automatically append the contents of the batch
C:> TYPE AUTOEXEC.BAT batch file automatically displayed
@ ECHO OFF
C: \ CPAV \ BOOTSAFE
(8) output to a printer to print the content or format of the print control code: ECHO printer control codes> PRN
ECHO print the contents of> PRN
The following example is input to the M-1724 printer to print control codes. <Alt> 156 is a small keyboard, hold down the Alt key, type 156, a similar situation and so on:
C:> ECHO +156 +42 +116> PRN (enter underscore command FS * t)
C:> ECHO +155 @> PRN (Enter the initialization command ESC @)
C:> ECHO.> PRN (line)
(9) the horn sounded
C:> ECHO ^ G
"^ G" in the dos window using Ctrl + G or Alt +007 input, the input can produce more than ^ G ringing sound. Method is used to add the batch file directly or make a batch file called.
Here "^ G" is the use of special symbols, see the section later in this article

3, PAUSE
PAUSE, play the game people know the meaning of suspension here is to stop the implementation of system commands and displays the following.
Example:
PAUSE
Operation display:
Press any key to continue...
Other tips to display language can be used:
Echo Other suggested language & pause> nul
4, errorlevel
Program return code
echo% errorlevel%
Run the end of each command, you can use this command line format to view the return code is used to determine whether the command executed successfully earlier default value is 0, the general command execution error will set errorlevel to 1

5, title
Set cmd window title
new title title # cmd window you can see the title bar has changed
6, COLOR
Sets the default console foreground and background colors.
COLOR [attr]
attr Specifies color attribute of console output Color attributes specified by the two hexadecimal digits - the first as the background, and the second was prospects. Each number can be any of the following values:
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = light green
3 = l. B = light blue light green
4 = Red C = Light Red
5 = Purple D = light purple
6 = ** E = light **
7 = White F = bright white, if not given any arguments, this command will restore the color to the color when CMD.EXE started. This value comes from the current console window, / T switch or
DefaultColor registry value.
If you use the same foreground and background colors to execute commands COLOR, COLOR command sets ERRORLEVEL to 1.
For example: "COLOR fc" produces light in bright red on white

7, mode configuration system device configuration system equipment.
Serial port: MODE COMm [:] [BAUD = b] [PARITY = p] [DATA = d] [STOP = s]
[To = on | off] [xon = on | off] [odsr = on | off]
[Octs = on | off] [dtr = on | off | hs]
[Rts = on | off | hs | tg] [idsr = on | off]
Device Status: MODE [device] [/ STATUS]
Print Redirection: MODE LPTn [:] = COMm [:]
Selected code page: MODE CON [:] CP SELECT = yyy
Status code page: MODE CON [:] CP [/ STATUS]
Display mode: MODE CON [:] [COLS = c] [LINES = n]
Keystroke rate: MODE CON [:] [RATE = r DELAY = d]
Example:
mode con cols = 113 lines = 15 & color 9f
This command sets the DOS window size: 15 lines, 113
8, GOTO and:
GOTO will point programming friends will know that this is meant to jump.
In the batch allowed to ": XXX" to build a label, and then jump to the label with the GOTO XXX: XXX place, and then execute the command after the label.
Example:
if {% 1 }=={} goto noparms
if "% 2 "=="" goto noparms
Tag name can easily play, but the best sense of the strings you, add a colon before the string is the label used to indicate, goto command is based on the colon (:) to find the next jump to get there. Better to have someone that looks like you will understand your intentions ah.

Example:
@ Echo off
: Start
set / a var + = 1
echo% var%
if% var% leq 3 GOTO start
pause
Operation display:
1
2
3
4

9, find
In the file search string.
FIND [/ V] [/ C] [/ N] [/ OFF [LINE]] "string" [[drive:] [path] filename [...]]
/ V Displays all lines not containing the specified string.
/ C show only the rows that contain the string.
/ N display line numbers.
/ I search for a string ignoring case.
/ OFF [LINE] Do not skip files with offline attribute set.
"String" specifies the text to search for string
[Drive:] [path] filename
Search for files specified.
If you do not specify a path, FIND will search type or text generated by another command.
Find and type the command often used in combination
Type [drive:] [path] filename | find "string" [> tmpfile] # select the line that contains string
Type [drive:] [path] filename | find / v "string" # exclude file contains the line string
Type [drive:] [path] filename | find / c # display file will use the number of lines above the prompt removal of native language find the command (the file name prompt)

Example:
@ Echo off
echo 111> test.txt
echo 222>> test.txt
find "111" test.txt
del test.txt
pause
Run as follows:
---------- TEST.TXT
111
Press any key to continue...

Example:
@ Echo off
echo 111> test.txt
echo 222>> test.txt
type test.txt | find "111"
del test.txt
pause
Run as follows:
111
Press any key to continue...

10, start the command batch command to call an external program (the external program running in a new window, the batch process to continue downward, ignoring the operational status of an external program), if the external program must be directly run an external program such as the completion continue to implement the rest of the instructions after the case: start explorer d: \
Open the D drive called graphical interface

11, assoc and ftype
File association
assoc set the 'file extension' association, related to the 'file type'
ftype to set the 'file type' association, linked to 'the implementation of procedures and parameters'
When you double click a. Txt file, windows are not based on. Txt notepad.exe to open it directly with the first judge to judge. Txt is txtfile 'file type'
Then call the associated command-line txtfile txtfile =% SystemRoot% \ system32 \ NOTEPAD.EXE% 1
In the "Folder Options" → "File Types" in the association to amend the 2
assoc # show all 'file extension' association
assoc. txt # display. txt on behalf of the 'file type' results. txt = txtfile
assoc. doc # show. doc on behalf of the 'file type' results. doc = Word.Document.8
assoc. exe # show. exe on behalf of the 'file type' results. exe = exefile
ftype # show all 'file types' association
ftype exefile # show exefile command line associated with the type, the results show exefile = "% 1"% *
assoc. txt = Word.Document.8
Set. Txt to word types of documents, you can see. Txt file icon has changed
assoc. txt = txtfile
Recovery. Txt the correct association

ftype exefile = "% 1"% *
The correct recovery exefile association if the association has been destroyed, you can run command.com, and then enter this command
12, pushd and popd
Change the current directory
@ Echo off
c: & cd \ & md mp3 # in the C: \ build mp3 folder
md d: \ mp4 # in D: \ build mp4 folder
cd / dd: \ mp4 # change the current directory to d: \ mp4
pushd c: \ mp3 # save the current directory, and change the current directory is c: \ mp3
popd # restore the current directory is just saved d: \ mp4
General usefulness in the current directory name is uncertain, it will be helpful. (Dos programming useful)

13, CALL
CALL command can be invoked during the execution of the batch to another batch, when another batch after the implementation, and then continue with the original batch
CALL command
Call a batch command, and direct the same effect as the command, is useful under special circumstances, such as multi-level nested variables, see later in the tutorial. In batch programming, certain conditions can generate command string with a call for the implementation of the string, see the example.
CALL [drive:] [path] filename [batch-parameters]
Call other batch program. filename parameter must have. bat or. cmd extension.
CALL: label arguments
Call the command section of this document, the equivalent of subroutines. The command section is called to label: label at the beginning of the command goto: eof end.
In addition, the batch script text parameter reference (% 0,% 1, etc.) has been changed as follows:
The% * batch script that all the parameters (such as% 1% 2% 3% 4% 5 ...)
Batch parameters (% n) of the alternative has been enhanced. You can use the following syntax: (do not understand the following examples of direct operation)
% 1 - remove the quotation marks ("), the expansion of% 1
% ~ F1 -% 1 expanded to a fully qualified path name
% ~ D1 - only 1% to a drive letter to expand
% ~ P1 -% 1 extend only to a path
% ~ N1 - only 1% to a file name extension
% ~ X1 -% 1 only expanded to a file extension
% ~ S1 - expanded path contains short names refer to
% ~ A1 -% 1 to file attributes expanded
% ~ T1 - the% 1 extension to file date / time
% ~ Z1 -% 1 expanded to the size of the file
% ~ $ PATH: 1 - Find out the directory in the PATH environment variable, and% 1
Expanded to find the first fully qualified name. If the environment
Variable name is not defined, or not find the file, this key combination will
Expanded to an empty string symbol can be combined to get multiple results revised:
% ~ Dp1 - expands% 1 to only the drive letter and path
% ~ Nx1 - only expands% 1 to a file name and extension
% ~ Dp $ PATH: 1 - listed in the PATH environment variable in the directory to find% 1
And extended to the first file found in the drive letter and path.
% ~ Ftza1 - expands% 1 to a DIR like output line.
In the above examples% 1 and PATH can be replaced by other valid values.
% ~ Syntax is terminated by a valid argument number. % Revised character can not be used with% * Note: The argument expands to ignore whether the file represented by the parameters of real, are in the current directory to extend the knowledge to understand the above, the following example is crucial.
Example:
@ Echo off
Echo creates a temporary file> tmp.txt
Rem down first save the current directory, and then c: \ windows set to the current directory
pushd c: \ windows
Call: sub tmp.txt
Rem restore the previous current directory down
Popd
Call: sub tmp.txt
pause
Del tmp.txt
exit
: Sub
Echo remove the quotation marks:% 1
Echo expanded to the path:% ~ f1
Echo expanded to a drive letter:% ~ d1
Echo expanded to a path:% ~ p1
Echo expanded to a file name:% ~ n1
Echo expanded to a file extension:% ~ x1
Echo expansion path that contains a short name:% ~ s1
Echo extension to file attributes:% ~ a1
Echo expanded to document the date / time:% ~ t1
Echo expanded to the size of the file:% ~ z1
Echo extended to a drive letter and path:% ~ dp1
Echo extension to the file name and extension:% ~ nx1
DIR Echo extends to a similar output line:% ~ ftza1
Echo.
Goto: eof
Example:
set aa = 123456
set cmdstr = echo% aa%
call% cmdstr%
pause
In this case, if not call, and direct running% cmdstr%, will display the results% aa%, rather than 123456

14, shift
Batch file to change the position of replaceable parameters.
SHIFT [/ n]
If command extensions are enabled, SHIFT command supports the / n command line switch; the command line switch tells the command started from the first n parameter shift; n range between zero and eight. For example:
SHIFT / 2
Would shift% 3 to% 2, translocated to% 3% 4, etc.; and does not affect the% 0 and% 1.

15, IF
IF conditional statement syntax is as follows:
IF [NOT] ERRORLEVEL number command
IF [NOT] string1 == string2 command
IF [NOT] EXIST filename command
The following elaborate, more detailed analysis see the back section.

(1) IF [NOT] ERRORLEVEL number command
IF ERRORLEVEL the sentence must be placed behind a single command, the command after the IF ERRORLEVEL command to determine the return value.
Number of figures ranging from 0 to 255, to determine the order of the time value should be descending. Returns a value greater than equal to the specified value, the condition is true Example:
@ Echo off
dir c:
rem exit code is> = 1 to jump to the implementation of Title 1,> = 0 0 implementation to go to the title
IF ERRORLEVEL 1 goto 1
IF ERRORLEVEL 0 goto 0
Rem above two lines can not exchange places, or failed also shown success.
: 0
echo command is successful!
Rem exit program is finished at the exit jump title
goto exit
: 1
echo command failed!
Rem exit program is finished at the exit jump title
goto exit
: Exit
pause
Run the show: The command completed successfully!
(2) IF [NOT] string1 == string2 command
string1 and string2 are the data for the character, the English will be considered in the case of characters is different in this condition must be equal to the number two (absolute equality means)
Equal, the command after the implementation of the back
Test to judge the current value of the variable, in order to prevent the string contains spaces, use the following format
if [NOT] {string1} == {string2} command
if [NOT] [string1] == [string2] command
if [NOT] "string1" == "string2" command
The wording actually parentheses or quotation marks as part of the string, as long as both sides agreed the equal sign on the line, such as writing to the following way:
if {string1} == [string2] command

(3) IF [NOT] EXIST filename command
EXIST filename for the file or directory exists in the mean
echo off
IF EXIST autoexec.bat echo file exists!
IF not EXIST autoexec.bat echo file does not exist!
This batch we can drive on the C drive and D, respectively, perform and see
16, setlocal content of this article with reference to the variable delay [Heroes Release] batch tutorial:
To Advanced, variable delay is a must shut off! Therefore, this part of the hope you will seriously look at.
In order to better illustrate the problem, we first introduce an example.
Example 1:
@ Echo off
set a = 4
set a = 5 & echo% a%
pause
Results: 4
Commentary: Why is it 4 instead of 5? Before the echo had clearly changed the variable to a value of 5 it?
Let us first look at the mechanism of the batch run the command:
Batch read commands are read by rows (the other example, for orders, then closed with a pair of parentheses, all statements are treated as one line), before proceeding to complete the necessary pre-work, with one including the line of command in the variable. We now analyze the cases of 1, a batch run to the phrase "set a = 5 & echo% a%" before the first sentence to read this sentence and made a pre - assigned a value of variable a, then% a% of course, is 4 it! (Not why, the batch is done.)
In order to be able to sense the dynamic changes of environment variables, batch design of the variable delay. Simply put, a full statement read after the variables are not immediately assigned to the line, but will perform in a single statement again before the assignment, that "delay" on the variable assignment.
So how to open the variable delay it? Variable delay and need to pay attention to? For example explain:
Example 2:
@ Echo off
setlocal enabledelayedexpansion
set a = 4
set a = 5 & echo! a!
pause
Results: 5
Commentary: Start of the variable delay, get the correct answer. Variable delay in the start statement is "setlocal enabledelayedexpansion", and a pair of variables to use an exclamation mark "!!" Enclosed (note use of the exclamation mark in English), otherwise there would be no delayed variable results.
Analyze the cases of 2, the first "setlocal enabledelayedexpansion" open variable delay, and then "set a = 4" give the assignment to a variable
4, "set a = 5 & echo! A!" a phrase is assigned to the variable 5 and the output (due to start a variable delay, so the batch can sense the dynamic changes, that is, not give the line variable assignment, and is assigned to variables during the operation, so this time a value is 5 a).
Another example of consolidating.
Example 3:
@ Echo off
setlocal enabledelayedexpansion
for / l%% i in (1,1,5) do (
set a =%% i
echo! a!
)
pause
Results:
1
2
3
4
5
Explanation: This example opens the variable delay and use "!!" Variable expansion up, so get our desired results. If you do not have the variable delay what will result? The result is this:
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
ECHO is off.
That is not for perceived dynamic changes in the statement.
Tip: do not open the variable delay in the case of a command line, change the variables must be reflected to the next command. This can also be used to see examples.
Example: swap two variable values, and no intermediate variables
@ Echo off
:: Objective: exchange value of two variables, but does not use a temporary variable
:: Code by JM 2007-1-24 @ XP CMD
:: Source: http://www.cn-dos.net/forum/viewthread.php?tid=27078
set var1 = abc
set var2 = 123
echo Exchange ago: var1 =% var1% var2 =% var2%
set var1 =% var2% & set var2 =% var1%
echo after the exchange: var1 =% var1% var2 =% var2%
pause

17, ATTRIB Displays or changes file attributes
ATTRIB [+ R |-R] [+ A |-A] [+ S |-S] [+ H |-H] [[drive:] [path] filename] [/ S [/ D]]
+ Set the property.
- Clear the property.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
[Drive:] [path] [filename]
Designated to handle the file attributes.
/ S handle the current folder and its subfolders in the matching documents.
/ D also handles folder.

Example:
md autorun
attrib + a + s + h autorun
The above command will create a folder autorun, and then set it to archive, system, hidden attributes

Special symbols used in section II
1, @ command line Shield character echo
2,% batch variables leading char
3,> redirection operator
4,>> redirection operator
5 ,<,>&,<& redirector
6, | command pipe character
7, the ^ escape character
8, & combination of command
9, & & combined orders
10, | | combination of command
11, "" string delimiter
12, comma
13; semicolon
14, () brackets
15! Exclamation point
16, the batch may be seen in other special tags: (abbreviated)
CR (0D) command-line terminator
Escape (1B) ANSI escape character leading char
Space (20) commonly used parameters delimiter
Tab (09); = delimiter is not commonly used parameters
+ COPY command file connector
*? File wildcard
/ Parameters switch leading char
: Batch tab leading char

BS, began to speak out
1, @ command line Shield character echo
This character means in a batch echo off the current line. We used to know a few lessons
ECHO OFF to close out the echo batch command, but can not turn off the ECHO OFF This command ECHO OFF now we add a @ before the command, the command can not meet all the requirements of the echo

2,% batch variables to guide the percent sign character is not really strict orders, it is just a batch of parameters only (with the use of more than% except in the case, will be detailed later.)
Reference variable with the% var%, caller external parameters with% 1 to% 9, etc.
% 0% 1% 2% 3% 4% 5% 6% 7% 8% 9% * for the command-line parameters passed to the batch
% 0 batch file itself, including the full path and extension
% 1 the first argument
% 9 ninth parameter
% * Starting from the first parameter to all parameters parameters% 0 has a special function, you can call the batch itself, in order to achieve the purpose of the batch cycle itself, or you can copy the file itself and so on.
Example: The simplest method of copying the file itself
copy% 0 d: \ wind.bat
Tip: Add inline comments
% Note the contents of% (can be used as inline comments, can not appear redirection symbol and the pipe symbol)
Why is it so? At this point, "notes the contents" is actually used as the variable, its value is empty, so the only effect from the comments, but this usage is prone to syntax errors, generally do not.

3,> redirection symbol redirects command output means is to pass the character and covered the role he is to run the result is passed to the back of the range (the back can be a file, it can be the default system console)
In the NT series of command line, redirected the scope of action by the entire command line into a single command statement, by the command separator &,&&,|| and block constraints limit.
For example:
Use the command: echo hello> 1.txt will create the file 1.txt, says "hello" (note that there is a trailing space)
Use the command: echo hello> 1.txt will create the file 1.txt, says "hello" (Note that end of the line with no spaces)

4,>> redirection symbol redirects command output this symbol of the role and> somewhat similar, but their difference is that>> is passed, and append the file, but> that covers the use of an example above uses the same take 1.txt command:
echo hello> 1.txt
echo world>> 1.txt
1.txt this time as follows:
hello
world

5 ,<,>&,<& redirection pipe character is the command of these three commands, but they are generally not used, you only need to know about ok, of course, if you want to study carefully, you can check their own data. (I have checked, the Internet still can not find relevant information)
<, Enter the redirect command, read from a file into the command input, rather than read from the keyboard.
@ Echo off
echo 2005-05-01> temp.txt
date <temp.txt
del temp.txt
This can not wait for input to directly modify the current date
"&, The output will be written to a handle the input of another handle.
<&, Just and "& the contrary, read input from one handle to another handle and write the output.
Common handle: 0,1,2, defined handle :3-9
1> nul that prohibited the export of correct information
2> nul that prohibit the output error message.
1 and 2 which are representative of a data stream input and output of the address (NT CMD called the handle, MSDOS called the equipment).
Handle 0: standard input stdin, keyboard input handle 1: standard output stdout, the output to the command prompt window (console, code-CON)
Handle 2: standard error stderr, output to the command prompt window (console, code-CON)
Stdin which may be <redirect, stdout can be>,>> redirection.
We already know the contents of the text read for the command can be used, if only for the command to read the first line with a bit of trouble. Simple approach is as follows:
@ Echo off
set / p str = <% 0
echo% str%
pause
Run the show the first line of the batch file itself: @ echo off
6, | command pipe character format: the first command | the second command [| Third command ...]
The results of the first command as the second argument to the command to use, remember that in this way is common in unix.
For example:
dir c: \ | find "txt"
The above command is: find C: \ all, and found TXT string.
FIND function please use FIND /? Own view, without the format of the automatic formatting parameters, so I automatically formatted disk A
echo y | format a: / s / q / v: system
Used the format we know, and then enter y when trays to confirm whether the trays, this command with echo y and the | character to pass the results of the echo y format command to achieve the purpose of automatic input y (this commands are hazardous, when the test carefully)

7, the ^ escape character
^ Is a special symbol <,>,& leading character, in the order he signed the above three special features removed, just as a symbol not only to their use of their special significance.
Such as
echo test ^> 1.txt
The results are: test> 1.txt
He did not appended to the 1.txt in, huh. Only show out another, this can also be used as an escape character line continuation symbol.
A simple example:
@ Echo off
echo hero ^
Is ^
Good ^
Men
pause
Needless to say, try to understand yourself.
Why is the escape character on the end of the line continuation character can play a role? The reason is very simple, because at the end of each line there is an invisible sign, that is, carriage return, escape character at end of a line let the failure of the carriage, which has played a continued role of the line.

8, & combination of command syntax: the first order & second order [& third command ...]
&,&&,|| For the combination of command, by definition, multiple commands can be combined as a command to execute. This batch script is allowed, but with very extensive. Recognized as a batch command line do not recognize the number.
This symbol allows the use of a line more than 2 different commands, when the first command fails, the command does not affect the back.
Here & both sides of the command is executed in order, front to back execution.
For example:
dir z: \ & dir y: \ & dir c: \
Above command is shown continuously z, y, c disk content to ignore the existence of the tray
9, & & combination of command syntax: the first command & & second command [& & third command ...]
This way you can execute multiple commands simultaneously, when it comes to the implementation of the command will not execute an error after the command has not been an error if the command has been executed this command, and above all similar, but the difference is that the first order fails, it will not execute the command behind
dir z: \ & & dir y: \ & & dir c: \
10, | | combination of command syntax: the first command | | The second command [| | Third command ...]
This way you can execute multiple commands simultaneously, when a command fails after the implementation of the second command, when it comes to implementing the right behind the command will not execute the command, if no correct command has been executed all the commands;

Tip: Combine command and redirect the command must be used with the pipe command priority attention to the priority higher than redirect command, redirection command takes precedence over the combination of command problem: the C drive and D drive files and folders are listed to a.txt file. See example:
dir c: \ & & dir d: \> a.txt
After this implementation, only D-a.txt information! Why? Because the combination of the priority of the command does not redirect the priority of the high command! So when the phrase in the implementation of the Bank is divided into two parts: dir c: \ and dir d: \> a.txt, and not as you think these two parts: dir c: \ & & dir d: \ and> a.txt. To use the combination of command & & meet the subject requirements, have to write:
dir c: \> a.txt & & dir d: \>> a.txt
Thus, according to priority level, DOS will be divided into two parts this sentence: dir c: \> a.txt and dir d: \>> a.txt. Eighteen in a few cases the difference is rather special, worth studying it a try.
Of course there can also use the & command (they want to look at truth oh):
dir c: \> a.txt & dir d: \>> a.txt

11, "" double quotes allow the string delimiter in the string contains spaces, into a special directory can use the following method
cd "program files"
cd progra ~ 1
cd pro *
The above three methods can enter the program files to this directory
12, comma comma is equivalent to a space, in some cases, "" can be used as a space to make such
dir, c: \
13; semicolon semicolon, when the same command can be used with different objectives; to isolate, but the implementation of the same effect as an error occurs during execution, only to return the error report, but the program will perform. (Some people say not to continue, in fact, to test to know)
For example:
dir c: \; d: \; e: \; z: \
Above command is equivalent to
dir c: \
dir d: \
dir e: \
dir f: \
If one of the z disk does not exist, run the show: The system can not find the path specified. Then terminate the command execution.
Example: dir c: \; d: \; e: \ 1.txt
Above command is equivalent to
dir c: \
dir d: \
dir e: \ 1.txt
One file e: \ 1.txt does not exist, but the existence of e plate, there is an error message, but the command will execute.

Why? If the target path does not exist, then the termination of the Executive; If the path exists, only the file does not exist, then continue.

14, () parentheses in parentheses in the batch have a special role in programming the right and left bracket must be used in pairs, brackets can include multi-line commands that will be viewed as a whole, as a command line.
Brackets in the statement and if statement for common use for the nested loop or conditional statement, in fact, in parentheses () can also be used alone, see the example.
Example:
Command: echo 1 & echo 2 & echo 3
Can be written as:
(
echo 1
echo 2
echo 3
)
Writing the same effect as the above two, both spellings are considered to be a command line.
Note: The number of orders is considered a command line, if there was variable, involving the variable delay.

15! Exclamation nothing to say, in the variable delays used to represent variables that should be expressed as% var%! Var!, See the front of the setlocal command introduced.

Chapter DOS loop: for command Detailed

FOR speak before this, a quick first novice friends to tell you, if you do not know what the command directly in the CMD enter it below:
name /? this format look at the system gives the help file, such as for /? will help all of the FOR command to display! course, many rookie can not read .... why we have so many batch article !!!! I also take care of rookie, the FOR command with the explanatory notes in my own way!
Started:

First, the basic format
FOR%% variable IN (set) DO command [command-parameters]
%% Variable Specifies a single letter replaceable parameter.
(Set) to specify one or a group of files. You can use wildcards.
command specifies the command to execute for each file.
command-parameters
Specify the parameters for a specific command or command line switch.
Parameters: FOR There are 4 parameters / d / l / r / f the role of their use in the following example I am now about to explain the meaning of each parameter

Second, the parameter / d
FOR / D%% variable IN (set) DO command [command-parameters]
If set contains wildcards, then specify the directory name match, but not with the file name matched.
If the Set (which is what I have written "documents or order") contains wildcards (* and?), Will match with the Set each directory (instead of the specified files in the directory group) the specified Command .
This parameter is mainly used for the directory search, not search files to see examples of this
@ Echo off
for / d%% i in (c: \ *) do echo%% i
pause
C will run under the root directory of the names of all the printed directory, and file name of a no show!
In the coming one, such as the current path we want the name of the folder only play out 1-3 letters
@ Echo off
for / d%% i in (???) do echo%% i
pause
So if your current directory with the directory name is only 1-3 letters, will be displayed, there is no excuse not shown here, and asterisk? Issue of the role of N * denotes arbitrary characters, and? No. only know that the role of any one character, and give you a thinking subject!
@ Echo off
for / d%% i in (window?) do echo%% i
pause
Save to C drive under implementation, will show what? Yourself! Show: windows
/ D parameters can only display the current directory under the name, this we should pay attention!

Third, the parameter / R
FOR / R [[drive:] path]%% variable IN (set) DO command [command-parameters]
Check to [drive:] path to the root of a tree, point to each directory
FOR statement. If the / R after the directory is not specified, then the current directory. If you set only a single point (.) Character, then enumerate the directory tree.

Recursion above we know, / D can only display the current path of the directory name, now that / R is and directories related to his able Mani? Assured him than / D more power!
He can put the current path or the file you specify the name of all the reading, note the file name, what's the use to see examples!
Please note that 2 points:
1, set the file name if it contains wildcards (? Or *), the listed / R parameter to specify the directory and subdirectories used by the following set consistent with all the files, no matching files are not listed .
2, on the contrary, if the set for the specific file name, without wildcards, to enumerate the directory tree (that is listed in the directory and all subdirectories below), regardless of the set of the specified file exists. This is said before a single dot (.) Enumerate the directory tree is a token, a single point representing the current directory, but also as a file.
Example:
@ Echo off
for / rc: \%% i in (*. exe) do echo%% i
pause
Let's save this BAT where D drive and then do casual, I'll see, he C root directory, and subdirectories for each directory below lists all of the EXE files are coming!!!!
Example:
@ Echo off
for / r%% i in (*. exe) do @ echo%% i
pause
Parameter is not the same now! In front of the command did not add the C: \ that is, the search path, and he will search the current directory path, such as your BAT you put him in the d: \ test directory implementation, he will be the D: \ test directory and subdirectories below him a list of all the EXE file!!!
Example:
@ Echo off
for / rc: \%% i in (boot.ini) do echo%% i
pause
Run this example that enumerates all the directories c drive, there is boot.ini in order to name the directory can be changed to the following:
@ Echo off
for / rc: \%% i in (boot.ini) do if exist%% i echo%% i
pause
Search for files with this command really good. . . . . .
This argument we should understand it! Still full of fun bidding!

Fourth, the parameter / L
FOR / L%% variable IN (start, step, end) DO command [command-parameters]
Expressed in incremental form of the set from the beginning to the end of a sequence of numbers.
Therefore, (1,1,5) will have a sequence of 12 345, (5, -1,1) will have a sequence (54 321).
Using the iterative variable start value (Start #), then step through a range of values, until the termination value exceeds the set value (End #). / L will be through the Start # and End # compared to the implementation of iteration variables. If Start # is less than End #, it will execute the command. If the iteration variable exceeds End #, the command interpreter to exit the loop. You can also use a negative Step # way by decreasing step numerical value within this range. For example, (1,1,5) generates sequences of 12345, and (5, -1,1) is generated sequence (54 321). The syntax is:
This shows a bit dizzy looking at it! We see examples of not faint!
@ Echo off
for / l%% i in (1,1,5) do @ echo%% i
pause
Save the implementation to see results, he would print from the 12,345 figure that 5
(1,1,5) This parameter is expressed by 1 each time from 1 until 5 terminated!
And so will halo to print a figure P with ... good to meet everyone, see this example
@ Echo off
for / l%% i in (1,1,5) do start cmd
pause
Is shocked after the execution, how much 5 CMD window, Oh! If the (1,1,5) into (1,1,65535) what would happen, let me tell you, will open 65535 CMD window, you do not crash so much .... let you strong!
Of course we can also change the start cmd md%% i This will create a directory specified in the!!! Name is 1-65535
I read this was given to the parameters of a destructive nature, we look at the last parameter

Five parameters / F
\ Iterative and parse the command used to process the output file parsing, string and file contents. Use iteration to check the contents of the variable definitions or string, and use a variety of options to further modify the parse method option. Use options to specify which token token option should be passed as an iteration variable. Note: do not use the token option, / F will only check the first token.
Resolution process, including reading the output file, string or file content will be divided into separate lines of text and then parsing each line into zero or more tokens. Then by setting the value of the iteration variable to the token, call the for loop. By default, / F passes the first of each line of each file with a blank separator. Skip blank lines.

Detailed help format:
FOR / F ["options"]%% variable IN (file-set) DO command [command-parameters]
FOR / F ["options"]%% variable IN ("string") DO command [command-parameters]
FOR / F ["options"]%% variable IN ('command') DO command [command-parameters]
Quoted string "options" include one or more keywords to specify different parsing options. These keywords are:
eol = c - refers to the end of a line comment character (just one)
skip = n - refers to the beginning of the file number of lines is ignored.
delims = xxx - refers to the separator set. This replaces the space and the Tab key to the
The default delimiter set.
tokens = x, y, mn - which refers to a symbol on each line is passed to each iteration
The for itself. This will cause additional variable names of the distribution. mn
A range format. Symbols specified by nth mth. If
The last symbol character string asterisk
Then the additional variable will be after the last symbol resolution
Distribution and accept the line of text retention. After testing, the parameter most
Can only distinguish 31 fields.
usebackq - after use quotation marks (number 1 on the left side of the keyboard keys that `.)
When not using the parameters usebackq: file-set that file, but can not contain spaces
Double quotes for strings, the "string"
Single quotes for the command, the 'command'
When using the parameters usebackq: file-set, and "file-set" that documents are
When the file path or in the name spaces, you can use double quotes
Single quotes for strings, that is, 'string'
Command after the quotation marks indicate that the `command`

These are used for /? Command to get help information, directly copied.
Halo out! I'll give an example to help you to understand these parameters!

For command Example 1 :****************************************
@ Echo off
First, create a temporary file test.txt rem
echo; comment line, this is a temporary file, used to delete> test.txt
Section 12 echo 11 13 14 15 16>> test.txt
echo 21 segments, 22, 23, 24, 25, 26>> test.txt
echo 31 segment -32 -34 segment segment segment -33 -36 -35 segment segment>> test.txt
FOR / F "eol =; tokens = 1,3 * delims =, -"%% i in (test.txt) do echo%% i%% j%% k
Pause
Del test.txt
Run display the results:
11 13 14 15 16
21 23 24, 25, 26
31 33 -36 34 -35 Section paragraph, press any key to continue...
Why is that? Me explain:
eol =; semicolon begins a comment line
tokens = 1,3 * each line, paragraph 1, paragraph 3 and the remaining fields are assigned to the variable%% i,%% j,%% k
delims =, - (minus sign after a space) minus a comma and a space for the separator, a space must be placed at the end

For command Example 2 :****************************************
@ Echo off
FOR / F "eol = delims ="%% i in (test.txt) do echo%% i
Pause
Test.txt will display all the running, including comments, do not explain Kazakhstan.

For command Example 3 :****************************************
Other / F parameter to output the command can also look at the example of the results
@ Echo off
FOR / F "delims ="%% i in ('net user') do @ echo%% i
pause
So you name the machine out of all the account numbers to expand the content with two single quotation marks, says that when the command execution, FOR command will return the results of each line, add the "delims =" is to keep me cell line can display the entire line, without a space to show only the left one!

FOR essentially finished the basic usage of the FOR ... if you read the system to help, you will find him some special definition of the following variables, which I do not speak first. We are tired because of the bar! You do not Leia .... I'm tired

Chapter III of the variables in the FOR command
There are some variables in the FOR command, the usage of many of their friends do not know much novice, a feeling in their usage!

FOR the first to list all variables:
~ I - Remove any quotes ("), extended% I
% ~ FI -% I will be extended to a fully qualified path name
% ~ DI - only% I extended to a drive letter
% ~ PI -% I only extended to a path
% ~ NI -% I extend only to a file name
% ~ XI -% I extend only to a file extension
% ~ SI - expanded path contains short names
% ~ AI - the% I to file attributes expanded
% ~ TI - to% I extend to the file date / time
% ~ ZI -% I will be extended to the size of the file
% ~ $ PATH: I - Find out the directory in the path environment variable, and% I extend
To find the first fully qualified name. If the environment variable name
Not defined or the file is not found, this key combination will be expanded to
Empty string

We can see that each line has a capital letter "I", that I actually brought us the variable FOR, FOR statement we substitute the variable name is, what to write here.
For example: FOR / F%% z IN ('set') DO @ echo%% z
Here we substitute the variable name is z then we get that I changed to z, for example,% ~ fI to% ~ fz
The front of the% ~ p is the content of this syntax it!

Good start to explain:

A, ~ I - Remove any quotes ("), extended% I
The role of this variable, such as his description, delete the quotation marks!
We look at this example:
First create a temporary file temp.txt, reads as follows
"1111
"2222"
3333 "
"4444" 44
"55" 55 "55
Can create a BAT file code is as follows:
@ Echo off
echo ^ "1111> temp.txt
echo "2222">> temp.txt
echo 3333 ^ ">> temp.txt
echo "4444" 44>> temp.txt
echo ^ "55" 55 "55>> temp.txt
rem create temporary file above, notice the quotation marks unpaired escape character ^ to add, do not leave a space before the redirection symbol
FOR / F "delims ="%% i IN (temp.txt) DO echo%% ~ i
pause
del temp.txt
Executed, we look back CMD was as follows:
1111 # before the string was removed quotes
# 2222, inclusive of the quotes are the string removed
3333 "without the quotation marks before the string, followed by the quotation marks retained
4444 "44 # delete the quotation marks in front of the string, and keep the middle of the quotation marks
55 "55" 55 # delete the quotation marks in front of the string, and keep the middle of the quotes, press any key to continue...
And before the temp.txt compare the contents, we will find the first 1,2,5-line quotes are gone, and this is the role of ~ i remove the quotation marks!
Remove quotation marks rules are as follows (BAT brother added!)
1, exist if the sum of the string quotes, remove head and tail of the quotation marks;
2, if the quotation marks end of the string does not exist, then delete the first string of quotes;
3, if the string exists between quotation marks, quotation marks or only exist in the tail is not removed.
Tornado added: do not delete without a head, a head with tail removed.

Second,% ~ fI -% I will be extended to a fully qualified path name to see examples:
Save on the code to any one place, I put the desktop, right here.
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ fi
pause
After the show follows the implementation of
C: \ Documents and Settings \ Administrator \ Desktop \ test.bat
C: \ Documents and Settings \ Administrator \ Desktop \ test.vbs
When I put the code directly into%% ~ fi%% i
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% i
pause
Is displayed after the execution the following:
test.bat
test.vbs
By contrast, it is easy to see that there is no path, and this is the "% I will be extended to a fully qualified path name of the" role that is if the% i variable content is a file name, he will put the file absolute path where the print, not just simply print a file name, under their hands and experiments to find out!

C,% ~ dI - only% I extended to a drive letter to see an example:
Code below, I still perform on the desktop!
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ di
pause
After the show I CMD in the implementation of the following
C:
C:
Two files on my desktop to test.bat, test.vbs,%% ~ di role is, if the contents of the variable%% i is a file or directory name, he will put him where the disk file or directory printed symbols !

D,% ~ pI -% I only extended to a path, like the use of the above, he just does not print the print file name path
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ pi
pause
I do not play the result, and we see the result copy the code it yourself, here are a few usage of such a code to come out, we all see the results now!

E,% ~ nI -% I extend only to a file name to print only the file name
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ ni
pause

VI,% ~ xI -% I only extended to print a file extension file extension only
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ xi
pause

VII,% ~ sI - expanded path contains short names only print short file name is absolutely
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ si
pause

VIII,% ~ aI - the% I extend to print the file attributes file attributes
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ ai
pause

IX,% ~ tI - to% I extend to the file date / time to print the file created date
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ ti
pause

Ten,% ~ zI -% I will expand to the size of the file size of print files
FOR / F "delims =="%% i IN ('dir / b') DO @ echo%% ~ zi
pause
In the example above "delims ==" can be changed to "delims =", that is not a separator

XI,% ~ $ PATH: I - Find out the directory in the path environment variable, and% I extend
To find the first fully qualified name. If the environment variable name
Not defined or the file is not found, this key combination will be expanded to
Empty string This is the last one, those are not the same as above, I am alone talk about!

And then save the code in the batch, on the desktop.
@ Echo off
FOR / F "delims ="%% i IN ("notepad.exe") DO echo%% ~ $ PATH: i
pause
Tornado added: The above code shows the results for the C: \ WINDOWS \ system32 \ notepad.exe
What he meant to the PATH variable in the path specified in the search notepad.exe file, if notepad.exe is the absolute path where he printed out, there are no print an error!

Chapter batch variable batch variables, I took him into two categories, namely "system variables" and "Custom variables"
We turn now to the two variables Detailed!

First, the system variables to their values by the system to pre-defined criteria based on automatic assignment, that is, these variables define the system has given them the value of
We do not need to give him an assignment, we only need to call and order! Me to list them all!

% ALLUSERSPROFILE% Local Returns the "All Users" configuration file.
% APPDATA% Local Returns the application default location to store the data.
% CD% Local Returns the current directory string.
% CMDCMDLINE% local to return to start the current Cmd.exe the exact command line.
% CMDEXTVERSION% system returns the current "Command Processor Extensions," the version number.
% COMPUTERNAME% System Returns the name of the computer.
% COMSPEC% System Returns the command line interpreter exact path of the executable program.
% DATE% System returns the current date. Use the date / t command the same format. Generated by the Cmd.exe. For
date command for more information, see Date.
% ERRORLEVEL% System Returns the error code on a command. Usually non-zero value indicates an error.
% HOMEDRIVE% System Returns the user home directory to connect to the local workstation drive letter. Value based on the home directory set. User's home directory is in the "Local Users and Groups" in the specified.
% HOMEPATH% System Returns the full path of the user's home directory. Value based on the home directory set. User's home directory is in the "Local Users and Groups" in the specified.
% HOMESHARE% system returns the user's shared home directory network path. Value based on the home directory set. User's home directory is in the "Local Users and Groups" in the specified.
% LOGONSERVER% return verify the current logon session the local domain controller's name.
% NUMBER_OF_PROCESSORS% System installed on the computer specified in the number of processors.
% OS% System Returns the operating system name. Windows 2000 displays the operating system Windows_NT.
% PATH% system search path for executable file specified.
% PATHEXT% System Returns the operating system that the executable file extensions list.
% PROCESSOR_ARCHITECTURE% System returns the processor's chip architecture. Value: x86 or IA64-based
Itanium
% PROCESSOR_IDENTFIER% System returns the processor instructions.
% PROCESSOR_LEVEL% System returns the processor installed on your computer model.
% PROCESSOR_REVISION% System Returns the version number of processors.
% PROMPT% Local Returns the current command interpreter prompt settings. Generated by the Cmd.exe.
% RANDOM% System returns anywhere between 0 and 32767 decimal digits. Generated by the Cmd.exe.
% SYSTEMDRIVE% System Returns the root directory of Windows server operating system (ie, the system root directory)
Drive.
% SYSTEMROOT% system returns Windows server operating system root directory.
% TEMP% and% TMP% System and User return the current logged-on user using the application available to the default temporary directory.
Some applications require TEMP, and other applications require TMP.
% TIME% System Returns the current time. Use time / t command the same format. Generated by the Cmd.exe. For
time command for more information, see Time.
% USERDOMAIN% Local Returns the name of the domain user account.
% USERNAME% Local Returns the name of the currently logged on user.
% USERPROFILE% Local Returns the current user's configuration file.
% WINDIR% System Returns the operating system directory.

So many system variables, how do we know that he values what is it?
In the CMD, enter echo% WINDIR%
This would display a variable value of the!
Give practical examples, such as we have to copy the files to the current directory to start the account can be
copy d: \ 1.bat "% USERPROFILE% \" Start "menu \ Programs \ Startup \"
% USERNAME% Local Returns the name of the currently logged on user. Note that there are spaces in the directory to use quotation marks

There are other system variables, they represent a meaning, or an operation!
They are% 0% 1% 2% 3% 4% 5% 9 ...... until there is a% *
% 0 in this bit special, there are several layers of meaning, to talk about the% 1 -% 9 meaning.
% 1 returned the first parameter of the batch
% 2 returns the second parameter of the batch
% 3 -% 9, and so push the class back to the batch parameters against? In the end how a return to law?
We look at this example, save the following code into the C drive and then under test.BAT
@ Echo off
echo% 1% 2% 3% 4
echo% 1
echo% 2
echo% 3
echo% 4
Enter CMD, enter cd c: \
I then enter test.bat I first argument is the second parameter I is the third argument I pay attention to the middle of the fourth parameter space, we will see something like this:
I was the first parameter I is the second parameter is the third argument I I I is the fourth parameter is the first parameter I is the second parameter is the third parameter I is the fourth argument I contrast of code, % 1 is "I am the first parameter"% 2 is "I was the second argument"
How to understand it!

% 1 and% 9 of these can make a batch can be run with parameters, greatly improving the batch processing!

There is also a% * him what is it? His role is not large, just return the argument only, but he is a return to the value of all the parameters, do not need to enter% 1% 2 to determine one's

Examples
@ Echo off
echo% *
Also save into the C drive test.bat enter CMD, enter cd c: \
I then enter test.bat I first argument is the second parameter I is the third argument is the fourth argument I can see him once put out all the parameters are displayed

Good now compared to that in the special% 0

% 0 the value of this parameter is not returned, and he has two meanings!
The first layer of meaning: where the absolute path to return a batch example:
@ Echo off
echo% 0
pause
Save test.BAT run on the desktop will show the following results
"C: \ Documents and Settings \ Administrator \ Desktop \ test.bat"
He performed where the current batch print out the path, and this is where the absolute path to return a batch mean second meaning: infinite loop BAT
Example:
@ Echo off
net user
% 0
Save to BAT implementation, he will execute an infinite loop this command net user, until you manually stop.
Tornado added: In fact,% 0% 1 in front of the first argument is the argument, of course, is the batch file name (including path).
These are the batch number of system variables, in addition to a number of variables, they also said some of the features
FOR those that command, FOR variables have said, do not talk about it.
Second, the custom variable name suggests Italy, the custom variable is given by us to give him the value of the variable to use custom variables have to use the set command, and look at cases

相关文章
  • Advanced Course on the command line selection of CMD, eds (rpm) 2010-11-06

    Chapter I Section I often batch based on the internal command batch Introduction 1, REM, and:: 2, ECHO, and @ 3, PAUSE 4, ERRORLEVEL 5, TITLE 6, COLOR 7, mode configuration system equipment 8, GOTO and: 9, FIND 10, START 11, assoc and ftype 12, pushd

  • Added to the context menu command line CMD Fast Track 2011-05-04

    Many people like the command line in the CMD down operating a computer, I was one of them. How to quickly open CMD and navigate to the specified path? Many optimization software (such as optimization of the master) are provided to add context menu "C

  • In the CMD command line method to modify the Windows Registry 2011-09-21

    In the CMD command line method to modify the Windows registry and Hiv Technology Undocumented registry regedit parameters can be used in the cmd. regedit operating parameters REGEDIT [/ L: system] [/ R: user] filename1 REGEDIT [/ L: system] [/ R: use

  • Added to the context menu command line CMD Fast Track (for win7) 2010-11-19

    Original Address: http://www.unxmail.com/read.php?51 Many people like the command line in the CMD down operating a computer, I was one of them. How to quickly open CMD and navigate to the specified path? Many optimization software (such as optimizati

  • Command line import and export oracle database 2010-06-05

    Command line import and export oracle database Recently been using mysql as a database development project, may have a friend ask me one day a rookie import and export data oracle problem, because for some time before been engaged in oracle database,

  • Ubuntu boot into command line 2010-07-10

    Method 1: ubuntu 6.10 start in the alternative with the upstart init, the main script in / etc / event.d the following, by default, / etc, under no inittab file, but by default, though inittab does not exist, ubuntu replaced with upstart init, and in

  • Linux command line editing shortcuts 2010-07-11

    Linux command line editing shortcuts: history shows the command history list ↑ (Ctrl + p) display a command ↓ (Ctrl + n) show the next command! Num execute the command history list, the first num Order!! Enforcement of an order! ? string? implementat

  • Android SDK command line tools commonly used in 2010-09-16

    1. Startup and shutdown ADB Services (adb start-server and adb kill-server) Tested by the author, after a period of time to run the simulator, adb of the possible (in the Windows process can be found in the service, the service is used for the simula

  • Development of Linux command line utility 2010-09-21

    http://www.ibm.com/developerworks/cn/linux/shell/clutil/ This article will guide you to learn how to write even to the end user, simple enough Linux command line utility. This paper outlines best practices and reliable command-line start, and a detai

  • Ubuntu boot into the command line 2010-12-31

    Method One: ubuntu started at 6.10 instead upstart init, the main script in / etc / event.d the following, by default, / etc, there is no inittab file, but although the default inittab does not exist, ubuntu replaced with upstart init, but still, and

  • Windows command line based (on) 2011-01-14

    Windows command-line based Go to the original HTML file http://sites.google.com/site/ghenix/ Download . Directory 1. Introduction : Why use the command line 2. The basis of the file system 2.1 Partition and drive letter 2.2 File with the name 2.3 Fil

  • MySQL Command Line [mysql command line frequently used commands] 2010-09-06

    MySql Download: www.mysql.org The first one, mysql service start and stop net stop mysql net start mysql The second measure, landing mysql mysql-u username-p password mysql-uroot-p, enter your password after the prompt, enter 12345, then press Enter

  • From the windows command line and graphical user interface up and using SQL * PLUS 2011-10-11

    First, use the command line interface In all operating systems support SQL * Plus command line interface. To connect to a remote Oracle database, ensure that Oracle Net is installed and working properly. For more information, refer to Oracle9i Net Se

  • Firebug Guide (four) --- how to use the Firebug command line API to provide debugging js procedures (below) 2009-03-18

    Introduction: Firebug command line are in one of the most useful features. If you have been using Visual Studio (referred to as VS) the experience of development projects, they should know you in the use of VS debugging procedures, "the immediate win

  • Demonstrate a strong command line under linux - command-line log analysis buttoned 2010-02-11

    Demonstrate a strong command line under linux - command-line log analysis buttoned Recently, a need to analyze sql log. Have a more simple way, in linux or cygwin in the command line can be more easily achieve their goals, as follows, This is my cygw

  • Quick Edit Shell command line 2010-02-20

    This film article is true, make a backup, reproduced below: Author: robinswan From: LinuxSir.Org Abstract: For the Linux / Unix kernel obtained from the overall structure of such, to even the smallest of the small software application to the text to

  • Transfer must have the eight [cmd command line] 2010-03-11

    Transfer must have the cmd command line eight [] Articles Category: Operating system Must have the cmd command line eight [] 1, ping It is used to check whether the network or Internet connection speed smooth order. As a living network administrator

  • ruby interpreter's command line switches 2010-03-31

    Command-line switch Description Example -C Does not perform procedures, only the syntax checker ruby-c test.rb -W During program execution a warning message is given ruby-w test.rb -E Implementation of the quotes in the command line in the code ruby-

  • I committed the wrong command line Dos 2010-03-29

    After the Dos command line in the wrong committed, I will be recorded in this paper. 1. Set the environment variable set PATH = %..... mistake here is that both sides can not add an equal sign equal sign

  • Disabling Desktop Effects from the command line 2010-02-14

    <! - Icon and title -> Disabling Desktop Effects from the command line <! - / Icon and title --><!-- message -> Hi all I am using Feisty. I enabled Desktop Effects on an old NVidia GeForce2 Pro. I'm sure Ubuntu uses the newer NVidia driv