A more detailed doscommand description 1 echo and @ Echo command @ # Close single-line echo off # Close echo from the next line @ echo off # Close echo from the beginning of this line. Generally, the first line of batch processing is the echo on # enable echo from the next line # display the echo off status or echo on status. # output a "carriage return line feed", blank line # (same as ECHO, ECHO; echo + echo [Echo] echo/ECHO \) 2 errorlevelecho % errorlevel % each command ends, you can view the return code in the command line format. The default value is 0, if an error occurs during command execution, the errorlevel is set to 13 dir to display the folder content dir # To display files and subdirectories in the current directory DIR/A # To display files and subdirectories in the current directory, including hiding files and system files dir C:/A: d # display the directory dir C:/a:-D # in the current directory of drive C to display files dir C in the root directory of drive C: \/B/P #/B only displays the file name,/P display dir * on pages *. EXE/s directory displays all the. exe files in the current directory and the subdirectory 4 CD switch directory CD # enter the root directory CD # display the current directory CD/d: \ SDK # You can change the drive letter and directory 5 MD create directory md d at the same time: \ A \ B \ C # If D: \ A does not exist, an intermediate directory is automatically created. # If the command extension is disabled, type mkdir \ A \ B \ c. 6 RD Delete directory rd abc # Delete the ABC subdirectory in the current directory, which must be an empty directory RD/S/q D: \ Temp # delete D: \ Temp folder and Its subfolders and files,/Q quiet mode 7 del delete file del D: \ test.txt # delete a specified file, it cannot be a hidden, system, or read-only file del/Q/A/f d: \ temp \*. * Delete all files in the D: \ Temp folder, including hidden, read-only, and system files, excluding the subdirectory del/Q/A/f/s d: \ temp \*. * Delete D: \ Temp and all files in the subfolders, including hidden, read-only, and system files, excluding subdirectories 8. RENAME Command Ren D: \ Temp TMP # folder rename 9 CLS clear screen 10 type display file content type C: \ Boot. INI # display the content of the specified file. The program file usually displays garbled type *. TXT example displays the contents of all the. txt files in the current directory. 11 copy the copy file copy c: \ test.txt D: \ test. copy the c: \ test.txt file to D: \ and rename it to test. bakcopy con test.txt is waiting for input from the screen. Press Ctrl + Z then to enter the content. The input content is saved as the test.txt file con, which represents the screen. PRN indicates the printer, and NUL indicates that the copy 1.txt + 2.txt 3.txt and 2.txt files of empty devices are combined, save as 3.txt. If 3.txt is not specified, save to 1.txt copy test.txt + copy the file to yourself, in fact, the new title of the CMD window is modified. # The title bar of the CMD window is changed. 13 ver displays the system version. 14 label and Vol set the volume label. Vol # display the volume label. # display the volume label, at the same time, you are prompted to enter the new volume label Label C: system # Set the volume of drive C to system15 pause. Pause command 16 REM and :: comment command comment line do not execute Operation 17 Date and Time date and time date # display the current date, and prompt to enter a new date, press \ "press enter \" to skip the input date/T # only display the current date, do not prompt to enter a new date time # display the current time, and prompt to enter a new time, press \ "press enter \" to skip the input time/T # only display the current time, do not prompt to enter the new time 18 Goto and: Jump command: Label # line first: indicates that this line is a label line, the tag line does not perform the operation goto label # Jump to the line 19 find (external command) to find the command find \ "ABC \" C: \ test.txt in C: if the lines containing ABC strings cannot be found in the \ test.txt file, set errorlevel to 1 find/I "ABC" C: \ test.txt to find the lines containing ABC, ignore case-insensitive find/C \ "ABC \" C: \ test.txt display the number of rows containing ABC 20 more (external command) display more C: \ test.txt # display the file content of C: \ test.txt on a screen. 21. Tree shows the directory structure. Tree D: \ # display the file directory structure of disk D. 22. Execute multiple commands in sequence, whether or not the command is executedSuccessful23 & execute multiple commands in sequence. When an error occurs, the following command find \ "OK \" C: \ test.txt & Echo success if \ "OK \" is found, \ "Success \" is displayed, and 24 is not displayed if \ "OK \" is found | multiple commands are executed sequentially, when a correct command is executed, the command find \ "OK \" C: \ test.txt | echo fails. If \ "OK \" cannot be found, \ "not successful \" is displayed, 25 is not displayed if it is found | MPs queue command dir *. */S/A | find/C \". exe \ "pipeline command indicates to execute the Dir command first, and execute the find command next to the output result. The command line result is: output the number of. EXE files in the current folder and all subfolders. Type C: \ test.txt | more and more c: \ test.txt have the same effect. 26> and> output redirection command> clear the original content of the file and write it again> append the content to the end of the file. Instead of clearing the original content, the content originally displayed on the screen will be output to the specified file. If the specified file does not exist, the Type C of the file will be automatically generated: \ test.txt> If the file content is not displayed on the PRN screen, switch to the printer echo Hello World> con to display Hello World on the screen. In fact, all outputs are by default> con copy C: \ test.txt F:> NUL: copy the file. The \ "file copied successfully \" prompt is not displayed. However, if the f disk does not exist, an error message is displayed. Copy C: \ test.txt F:> NUL 2> NUL does not display the prompt message "file copied successfully". If the f disk does not exist, the error message echo ^ w ^> ^ W> C: \ test.txt is not displayed. The file content is ^ W> w ^ and> is a control command, to output them to a file, you must add a ^ symbol 27 <to get the input information from the file, instead of using the date time label on the screen. Wait for the command @ echo offecho> temp.txt date <temp.txt del temp.txt so that you can directly modify the current date 28% 0% 1% 2% 3% 4% 5% 6% 7% 8% 9% * without waiting for the command row passed to batch parameters % 0 batch file itself % 1 first parameter % 9 ninth parameter % * All parameter batch parameters starting from the first parameter (% N) has been enhanced. You can use the following syntax: % ~ 1-delete quotation marks (\ ") and expand % 1% ~ F1-extended % 1 to a fully qualified PATH % ~ D1-only expand % 1 to one drive letter % ~ P1-only expand % 1 to one path % ~ N1-only expand % 1 to one file name % ~ X1-only expand % 1 to one file extension % ~ S1-the expanded path contains the short name % ~ A1-extended % 1 To File Attribute % ~ T1-extend % 1 to the file date/time % ~ Z1-expand % 1 to the file size % ~ $ Path: 1-search for the Directory of the PATH environment variable and extend % 1 to the first fully qualified name. If the environment variable name is not defined, or the file is not found, the key combination is expanded to an empty string. You can combine the modifier to get multiple results: % ~ Dp1-only extend % 1 to drive letter and PATH % ~ Nx1-only extend % 1 to the file name and extension % ~ DP $ path: 1-find % 1 in the directory listed in the PATH environment variable, and extend it to the drive letter and path of the first file found. % ~ Ftza1-extend % 1 to a directory similar to DirTravel. Refer to call /? Or /? See the meaning of each parameter echo load \ "% 1 \" \ "% 2 \"> C: the file generated by \ test.txt is in the load \ "% 1 \" \ "% 2 \" batch processing file, output the command line parameters to the file 29 in this format. If is used to determine the command if \ "% 1 \" = \ "/A \" Echo, the first parameter is/AIF/I \" % 1 \ "equ \"/A \ "Echo. The first parameter is/a/I, indicating that it is case insensitive, EQU and = are the same. For other operators, see if /? If exist c: \ test. bat ECHO has c: \ test. BAT file if not exist C: \ WINDOWS (ECHO does not exist C: \ Windows Folder) If exist c: \ test. BAT (ECHO has c: \ test. BAT) else (ECHO does not exist c: \ test. BAT) 30 setlocal and endlocal set "command extension" and "extended environment variables" setlocal enableextensions # enable \ "command extension \" setlocal disableextensions # disable \ "command extension \" setlocal enabledelayedexpansion # enable \ "extended environment variables \" setlocal disabledelayedexpansion # disabled \ "extended environment variables \" endlocal # recovered to the use of setlocal statements In the previous status, "command extension" is enabled by default. "extended environment variable" is disabled. By default, the system automatically restores the default value. You can modify the Registry to disable the \ "command extension \", for more information, see CMD /?. We recommend that you add the setlocal enableextensions and endlocal statements at the beginning and end of the program that uses the \ "command extension, to ensure that the program can run correctly on other systems \ "Deferred Environment Variable Expansion \" is mainly used for the IF and for statement, in the description of set, you can add % before and after the variable name by setting the variable reference variable with the routine 31 set, that is, % variable name % set # to display all currently available variables, including system variables and custom variables echo % systemdrive % # display the system disk drive letter. System variables can directly reference set P # to display all variables starting with P. If one variable does not exist, set errorlevel = 1 Set P = aa1bb1aa2bb2 # Set Variable P, and assign the value = to the following string, that is, the aa1bb1aa2bb2echo % P % # string represented by the DISPLAY variable P, that is, aa1bb1aa2bb2echo % P :~ 6% # display all the characters after the 6th characters in the Variable P, that is, aa2bb2echo % P :~ 6, 3% #3 characters after 6th characters are displayed, that is, aa2echo % P :~ 0, 3% # display the first three characters, namely aa1echo % P :~ -2% # display the last two characters, b2echo % P :~ 0,-2% # display other characters except the last two characters, that is, aa1bb1aa2becho % P: AA = C % # Replace all AA in Variable P with C, display c1bb1c2bb2echo % P: AA = % # Replace all AA strings in Variable P with null, that is, display 1bb12bb2echo % P: * BB = C % # The first BB and all its previous characters are replaced with C, that is, c1aa2bb2set P = % P: * BB = C % # Set Variable P, assign a value of % P: * BB = C %, that is, c1aa2bb2set/a p = 39 # Set P to a numeric variable with a value of 39 set/a p = 39/10 # support operators, if there is a decimal number, use the detail method, 39/10 = 3.9, and get 3, P = 3 set/a p = P/10 # With the/a parameter, the variable after = can directly reference the operation set/a p = "1 & 0" # "and" without adding %. quotation marks are required. For other supported operators, see set /? Set P = # cancel the P variable set/P = enter the screen to display "enter ", the input string is assigned to the variable P. Note that this variable can be used to replace the choice command. Note that the variable is replaced all at once in the IF and for compound statements, for example, @ echo offset P = aaaif % P % = aaa (echo % P % Set P = BBB echo % P %) the result will show that aaaaaa has replaced all % P % with \ "replace \" in AAA when reading the if statement /? In the help, \ "extended \" and \ "extended environment variables \" can be enabled to "delay extended environment variables! To reference variables, that is! Variable name! @ Echo offsetlocal enabledelayedexpansionset P = aaaif % P % = aaa (echo % P % Set P = BBB echo! P!) The endlocal result will show several dynamic variables in aaabbb, running set cannot see % Cd % # indicates the string % date % # current date % time % # current time % random % # random integer, ranging from 0 ~ 32767% errorlevel % # current errorlevel Value % cmdextversion % # current command processor extension version % limit line % # Call the original command line of the command processor to view the value of each variable using the echo command, for example, Echo % time % note that % time % is accurate to milliseconds. When batch processing requires delayed processing, you can use 32 start to call external program commands in batch processing, otherwise, after the external program is completed, it will continue to execute the remaining command 33. Call the other batch processing command in the call batch, otherwise, the remaining batch processing commands will not be executed. Sometimes some applications use start to call errors. You can also call 34 choice (external command) to select a command for the user to enter a character.SelectRun different commands. The Returned Code errorlevel is 1234 ...... In win98, choice.comwin2000pro. from win98, choice.exe choice/n/c y/T 5/d y> NUL latency 5 seconds 35 assoc and FTYPE File Association assoc set 'file extension' Association, if 'file type' FTYPE plugin is used to determine whether to use notepad.exe to open the file first, then the TXT file belongs to the txtfile 'file type' and then the txtfile associated command line txtfile = % SystemRoot % \ system32 \ notepad is called. EXE % 1 can be modified in \ "Folder Options \" → \ "file type \". These two associated assoc # Show All 'file extension' associated Assoc. TXT example shows the 'file type' represented by. txt. The result is displayed. TXT = txtfi Leassoc. the "file type" represented by ". Doc" is displayed. doc = word. document.8assoc. EXE plugin displays the 'file type' represented by .exe, and the result is displayed. EXE = exefileftype # display all 'file type' associated with FTYPE exefile # display command lines associated with exefile type, the results show that the icons of the exefile = \ "% 1 \" % * assoc history file have all changed assoc .txtjwtxtfilerestore .txt correct association FTYPE exefile = \ "% 1 \" % * restore the correct association of exefile if the association has been damaged, you can run command.com, and then enter this command 36 pushd and popd to switch to the current directory @ echo offc: & CD \ & MD MP3 # create an MP3 file in c: \. Folder md d: \ MP4 # create the MP4 folder CD/D: \ MP4 # In D: \ # change the current directory to D: \ mp4pushd c: \ MP3 # Save the current directory, switch the current directory to c: \ mp3popd # it is complicated to restore the current directory to the saved D: \ mp437 for loop command. For more information, see /? Let's take a look at for % I in (C: D: e: F :) Do echo % I call each string in parentheses in sequence, and execute the command after do to pay attention to % I, in batch processing, the for statement calls parameters with 2% default string separators \ "Space key \", \ "tab key \", \ "Enter key \" for % I in (*. TXT) do find \ "ABC \" % I: Execute the find command for/R on all TXT files in the current directory. % I in (*. TXT) do find \ "ABC \" %iisearch the lines containing the ABC string in the current directory and all the TXT files in the subdirectory for/R. % I in (.) do echo % ~ PNI displays the current directory name and all subdirectory names, including paths, excluding the drive letter for/r d: \ MP3 % I in (*. MP3) Do echo % I> D: \ mp3.txt save the file names of MP3 files in D: \ MP3 and Its subdirectories to D: in \ mp3.txt, for/L % I in (2345678, 8) Do echo % I is used to generate a string of numbers. 2 is the beginning of the number sequence, and 8 is the end, 1 indicates that the output results of the SET command are repeatedly called each time 1for/F % I in ('set') Do echo % I is added, one for/f \ "EOL = p \" % I in ('set') Do echo % I get the output result of the SET command, ignore the rows starting with P for/F % I In (d: \ mp3.txt) Do echo % I show each file name in D: \ mp3.txt, one per line, spaces are not supported for/f \ "de LIMs = \ "% I In (d: \ mp3.txt) Do echo % I display each file name in D: \ mp3.txt, one per line, supports the result of the Dir command with a space name for/f \ "Skip = 5 tokens = 4 \" % A in ('dir') Do echo %, skip the first five rows, the delimiter between the remaining 4th columns and each column is the default \ "Space \". Note that the first five lines output by the Dir command are for/f \ "tokens = 1, 2 without file names., 3 delims =-\ "% A in ('date/t') Do (echo % A echo % B echo % C) output results for date/t, the first columns of Columns 1, 2, and 3 correspond to the specified % A. The following % B and % C are derived, specify-and \ "Space \" as separators for other columns. Note that delims =-is followed by a \ "Space \" where tokens = 1, 2. If tokens = 1-3 is used, the effect is the same for/f \ "tokens = 2 * delims =-\" % A in ('date/t ') do echo % B takes the 2nd column to % A, and the subsequent columns map the disk to % b38 SUBST (external command. Subst z: \ Server \ D # Enter Z: To access \ Server \ d subst z: /D # cancel the subing SUBST # display all current ing time 39 xcopy (external command) file copy xcopy D: \ MP3 E: \ MP3/S/e/I/y Copy D: \ MP3 folder, all subfolders and files to E: \, overwrite existing files and add/I to indicate if E: \ a new file is automatically created without an MP3 folder; otherwise, you will be asked