![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-04 07:52 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » Batch File Syntax [Repost] |
| Printable Version 746 / 6 |
| Floor1 zxgui | Posted 2007-04-20 01:57 |
| 初级用户 Posts 13 Credits 38 | |
|
Batch file syntax
Batch file syntax Files with the extension bat (under nt/2000/xp/2003 they can also be cmd) are batch files. ==== Note ======================================= .bat is a DOS batch file .cmd is another kind of batch file for the nt-kernel command-line environment From a broader point of view, unix shell scripts and text in other operating systems or even applications that is interpreted and executed by a shell also have very similar functions to batch files, and are likewise interpreted and executed line by line by a dedicated interpreter. A more general name for this kind of text form is scripting language. So to some extent, batch, unix shell, awk, basic, perl and other scripting languages are all the same; only their application scope and interpretation platform differ. Some applications even still use the term batch processing, but their contents and extensions are completely different from DOS batch files. =================================== First of all, a batch file is a text file. Each line in this file is a DOS command (most of the time just like a command line we execute at the DOS prompt). You can use Edit under DOS or any text file editing tool such as Windows Notepad (notepad) to create and modify batch files. ==== Note =================== A batch file can absolutely use non-DOS commands, and can even use ordinary data files without executable characteristics. This is due to the involvement of the new interpretation platform of the Windows system, which has made the application of batch files more and more "marginalized." So the batch processing we discuss should be limited to the DOS environment or command-line environment, otherwise many concepts and assumptions would need major changes. ======================== Second, a batch file is a simple program. You can control the flow of command execution through conditional statements (if) and flow-control statements (goto), and you can also use loop statements (for) in batch files to execute a command repeatedly. Of course, the programming ability of batch files is very limited compared with programming languages such as C, and it is also very non-standardized. The program statements of batch processing are DOS commands one by one (including internal commands and external commands), and the ability of batch processing mainly depends on the commands you use. ==== Note ================== A batch file (batch file) can also be called a batch program (batch program). This is different from compiled languages. For the C language, files with the extension c or cpp can be called C language files or C source code, but only the exe file after compilation and linking can be called a C program. Because a batch file itself has both the readability of text and the executability of a program, the boundaries between these terms are relatively vague. =========================== Third, every written batch file is equivalent to a DOS external command. You can put the directory it is in into your DOS search path (path) so that it can run from any location. A good habit is to create a bat or batch directory on the hard disk (for example C:BATCH), and then put all the batch files you write into that directory. Then as long as you set c:batch in path, you can run all the batch programs you wrote from any location. ==== Note ===== In a pure DOS system, executable programs can roughly be divided into five categories. In order from high to low execution priority they are: DOSKEY macro commands (resident in memory beforehand), internal commands in COMMAND.COM (loaded into memory at any time according to the memory environment), executable programs with the com extension (loaded directly into memory by command.com), executable programs with the exe extension (relocated and then loaded into memory by command.com), and batch programs with the bat extension (interpreted and analyzed by command.com, which according to their contents calls categories 2, 3, 4, and 5 of executable programs in priority order, analyzing one line and executing one line; the file itself is not loaded into memory) ============ Fourth, under DOS and Win9x/Me systems, the AUTOEXEC.BAT batch file in the root directory of drive C: is an auto-run batch file. This file runs automatically every time the system starts. You can put commands that need to be run every time the system starts into this file, such as setting the search path, loading the mouse driver and disk cache, setting system environment variables, etc. Below is an example of an autoexec.bat running under Windows 98: @ECHO OFF PATH C:WINDOWS;C:WINDOWSCOMMAND;C:UCDOS;COSTools; 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 ==== Note ===== AUTOEXEC.BAT is the auto-run batch file of the DOS system, interpreted and executed by COMMAND.COM at startup; and in the Win9x environment, not only were many other auto-run batch files such as DOSSTART.BAT and WINSTART.BAT added, but many variants such as .DOS .W40 .BAK .OLD .PWS were also added for AUTOEXEC.BAT to suit complex environments and changing needs. ==== Editor's note by willsort ============= There are many points in the following classification of commands that are worth examining. In the common commands, @ is not really a command, while dir and copy, which are also very commonly used, are not listed. And among the special commands, all of them are common commands to me. I suggest dividing the commands referenced by batch files into three categories: internal commands, external commands, and third-party programs. Among internal commands and external commands, there is another category specifically for or commonly used in batch files, which can be called "batch commands." The following is excerpted from the MS-DOS 6.22 help document about "batch commands." Of course, some concepts and definitions in it are already a bit outdated. Batch commands A batch file or batch program is a text file containing several MS-DOS commands, with the extension .BAT. When the name of the batch program is entered at the command prompt, MS-DOS executes the commands in that batch program as a group. Any command usable at the command prompt can be used in a batch program. In addition, the following MS-DOS commands are used especially in batch programs. ========== Common commands echo, @, call, pause, rem (small tip: use :: instead of rem) are the most commonly used commands in batch files. Let's start learning from them. ==== Note =========== First, @ is not a command, but a special marker in DOS batch processing, used only to suppress command-line echoing. Below are some special markers you may see in DOS command lines or batch files: CR(0D) command-line terminator Escape(1B) ANSI escape character introducer Space(20) commonly used parameter delimiter Tab(09) ; = infrequently used parameter delimiters + COPY command file concatenation symbol * ? file wildcards "" string delimiter | command pipe symbol < > >> file redirection symbols @ command-line echo suppression symbol / parameter switch introducer : batch label introducer % batch variable introducer Second, :: can indeed serve as a rem comment, and it is simpler and more effective; but there are two points to note: First, aside from ::, any line beginning with : is treated as a label in batch processing, and all content after it is ignored directly. Just to distinguish it from a normal label, it is recommended to use a label that goto cannot recognize, that is, immediately after : put a special symbol that is not alphanumeric. Second, unlike rem, a line after :: will not be echoed during execution, regardless of whether echo on is used to turn on command-line echoing, because the command interpreter does not regard it as a valid command line. From this point of view, rem is more suitable than :: in some situations; in addition, rem can be used in config.sys files. ===================== echo means display the characters after this command echo off means that after this statement, all commands that run will not display the command line itself @ is similar to echo off, but it is added at the very beginning of each command line, indicating that the command line of this line is not displayed during execution (it can only affect the current line). call calls another batch file (if you call another batch file directly without call, then after that batch file finishes executing, you will not be able to return to the current file and execute the subsequent commands in the current file). pause pauses batch execution when this line runs and displays the prompt Press any key to continue... on the screen, waiting for the user to press any key before continuing rem means the characters after this command are explanatory text (comments), not executed, only for your own future reference (equivalent to comments in a program). ==== Note ===== The description here is rather confusing. It is better to quote the command-line help for each command directly for clarity ------------------------- ECHO When a program runs, displays or hides the text in a batch program. It can also be used to enable or disable command echoing. When a batch program runs, MS-DOS generally displays (echoes) the commands in the batch program on the screen. Use the ECHO command to turn this function off. Syntax ECHO To use the echo command to display a command, use the following syntax: echo Parameters ON|OFF Specifies whether command echoing is enabled. To display the current ECHO setting, use the ECHO command without parameters. message Specifies the text for MS-DOS to display on the screen. ------------------- CALL Calls another batch program from one batch program without causing the first batch program to terminate. Syntax CALL filename Parameters filename Specifies the name and location of the batch program to call. The filename must use .BAT as the extension. batch-parameters Specifies the command-line information required by the batch program. ------------------------------- PAUSE Pauses execution of a batch program and displays a message prompting the user to press any key to continue. This command can only be used in batch programs. Syntax PAUSE REM Adds comments to a batch file or CONFIG.SYS. REM can also be used to mask commands (in CONFIG.SYS a semicolon ; can also be used instead of the REM command, but in a batch file it cannot replace it). Syntax REM Parameters string Specifies the command to mask or the comment to include. ======================= Example 1: Use edit to edit the file a.bat, enter the following content and save it as c:a.bat. After executing this batch file, the following can be done: write all files in the root directory to a.txt, start UCDOS, enter WPS, etc. The content of the batch file is: Command comments: @echo off Do not display subsequent command lines nor the current command line dir c:*.* >a.txt Write the file list of drive C to a.txt call c:ucdosucdos.bat Call ucdos echo 你好 Display "Hello" pause Pause, wait for a keypress to continue rem 准备运行wps Comment: prepare to run wps cd ucdos Enter the ucdos directory wps Run wps Parameters of batch files Batch files can also use parameters like functions in the C language (equivalent to the command-line parameters of DOS commands). This requires a parameter specifier "%". % means parameters. Parameters refer to strings added after the filename when running the batch file, separated by spaces (or Tab). Variables can be from %0 to %9. %0 represents the batch command itself, and the other parameter strings are represented in order by %1 to %9. Example 2: There is a batch file named f.bat in the root directory of C:, with the content: @echo off format %1 If you execute C:>f a: then when f.bat is executed, %1 means a:, so format %1 is equivalent to format a:, so what the above command actually executes is format a: Example 3: There is a batch file named t.bat in the root directory of C:, with the content: @echo off type %1 type %2 Then run C:>t a.txt b.txt %1 : means a.txt %2 : means b.txt So the above command will display the contents of the files a.txt and b.txt in sequence. ==== Note =============== In batch files, parameters are also treated as variables, so the percent sign is likewise used as the introducer, followed by a number from 0-9 to form a parameter reference. The relationship between the reference and the parameter (for example between %1 and a: in the above text) is similar to the relationship between a variable pointer and a variable value. When we want to reference the eleventh or more parameters, we must move DOS's parameter starting pointer. The shift command is what plays the role of moving this pointer; it moves the parameter starting pointer to the next parameter, similar to pointer operations in the C language. Diagram as follows: Initial state, cmd is the command name, which can be referenced with %0 cmd arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ | | | | | | | | | | %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 After 1 shift, cmd can no longer 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 shifts, arg1 is also discarded, and %9 points to empty, having no reference meaning cmd arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 ^ ^ ^ ^ ^ ^ ^ ^ ^ | | | | | | | | | %0 %1 %2 %3 %4 %5 %6 %7 %8 Unfortunately, neither win9x nor DOS supports the reverse operation of shift. Only in the nt-kernel command-line environment does shift support the /n parameter, allowing repeated movement of the starting pointer based on the first parameter. ================= Special commands if goto choice for are relatively advanced commands in batch files. If you use these very skillfully, then you are an expert at batch files. 1. if is a conditional statement, used to determine whether specified conditions are met, and then decide which command to execute. There are three formats: 1. if "parameter" == "string" command to execute If the parameter is equal to (not means not equal, same below) the specified string, then the condition is met and the command is run; otherwise the next line is run. Example: if "%1"=="a" format a: ==== In if command-line help, the description of this point is: IF string1==string2 command The following points need attention here: 1. The double quotes containing the string are not required by the syntax, but are just a customary "anti-empty" character 2. string1 is not necessarily a parameter; it can also be an environment variable, loop variable, or other string constant or variable 3. command is not required by the syntax either; a space after string2 can already form a valid command line ============================= 2. if exist filename command to execute If the specified file exists, then the condition is met and the command is run; otherwise the next line is run. For example: if exist c:config.sys type c:config.sys means that if the file c:config.sys exists, then display its contents. ****** Note ******** The following usage can also be used: if exist command device refers to devices already loaded in the DOS system. Under win98 there are usually: AUX, PRN, CON, NUL COM1, COM2, COM3, COM4 LPT1, LPT2, LPT3, LPT4 XMSXXXX0, EMMXXXX0 A: B: C: ..., CLOCK$, CONFIG$, DblBuff$, IFS$HLP$ The exact contents will vary slightly depending on the hardware and software environment. When using these device names, the following three points must be ensured: 1. The device really exists (except for software-virtualized devices) 2. The device driver has been loaded (standard devices such as aux and prn are defined by the system by default) 3. The device is ready (mainly refers to a: b: ..., com1..., lpt1..., etc.) You can use the command mem/d | find "device" /i to inspect the devices loaded in your system Also, in the DOS system, devices are also regarded as a special kind of file, and files can also be called character devices; because both devices and files are managed by handles, and a handle is a name, similar to a file name, except that handles are not used for disk management but for memory management. So-called device loading means allocating a referable handle for it in memory. ================================== 3. if errorlevel <number> command to execute Many DOS programs return a numeric value after running to indicate the result (or status) of the program. Through the if errorlevel command you can judge the return value of the program, and decide which command to execute according to different return values (the return values must be arranged in descending order). If the return value is equal to the specified number, then the condition is met and the command is run; otherwise the next line is run. For example if errorlevel 2 goto x2 ==== Note =========== Arranging return values from high to low is not required, but is only customary usage when the executed command is goto. When set is used as the executed command, they are usually arranged from low to high. For example, if you need to put the return code into an environment variable, you need to use the following order: 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, the following loop can also be used instead; the principle is the same: for %%e in (1 2 3 4 5 6 7 8...) do if errorlevel %%e set el=%%e For more efficient and concise usage, you can refer to another article I wrote about obtaining errorlevel The reason this phenomenon occurs is that the judging condition of if errorlevel when comparing return codes is not equal to, but greater than or equal to. Due to the jump characteristics of goto, sorting from low to high will cause an exit at a smaller return code; and due to the "repeated" assignment characteristic of the set command, sorting from high to low will cause a smaller return code to "overwrite" a larger return code. In addition, although if errorlevel=<number> command is also a valid command line, it is only because command.com ignores = by treating it as a command-line separator when interpreting the command line =========================== 2. goto When a batch file runs to here, it will jump to the label specified by goto (a label is defined by : followed by a standard string). The goto statement is generally used together with if to execute different command groups according to different conditions. For example: goto end :end echo this is the end A label is defined with ":string", and the line where the label is located is not executed. ==== Editor's note by willsort label is often translated as "标签", but this does not have a widely established convention. Used together, goto and : can achieve jumps in the middle of execution, and combined with if can achieve conditional branches in the execution process. Multiple if statements can achieve grouping of commands, similar to the switch case structure in C or the select case structure in Basic. Large-scale and structured command grouping can achieve the function features in high-level languages. The following is a comparison of syntactic structures between batch processing 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() ================================== 3. choice Using this command, the user can enter one character (for selection), and then according to the user's selection different errorlevel values are returned, which are then used with if errorlevel to run different commands according to the user's selection. Note: the choice command is an external command provided by DOS or Windows systems. The syntax of the choice command differs slightly between versions; please use choice /? to check usage. Command syntax for choice (this syntax is that of the choice command in Windows 2003; the command syntax of choice in other versions is generally similar): CHOICE Description: This tool allows users to select one item from a list of choices and returns the index of the selected item. Parameter list: /C choices Specifies the list of choices to create. The default list is "YN". /N Hides the list of choices in the prompt. The message before the prompt is displayed, and the choices are still enabled. /CS Allows case-sensitive choices. By default, this tool is not case-sensitive. /T timeout The number of seconds to pause before making the default choice. Acceptable values are from 0 to 9999. If 0 is specified, there is no pause, and the default choice will be selected. /D choice Specifies the default choice after nnnn seconds. The character must be in the set of choices specified with the /C option; at the same time, nnnn must be specified with /T. /M text Specifies the message to display before the prompt. If not specified, the tool only displays the prompt. /? Displays help information. Notes: The ERRORLEVEL environment variable is set to the key index selected from the choice set. The first listed choice returns 1, the second returns 2, and so on. If the user presses a key that is not a valid choice, the tool will emit a warning beep. If the tool detects an error condition, it returns an ERRORLEVEL value of 255. If the user presses Ctrl+Break or Ctrl+C, the tool returns an ERRORLEVEL value of 0. When using the ERRORLEVEL parameter in a batch program, arrange the parameters in descending order. Examples: CHOICE /? CHOICE /C YNC /M "Press Y to confirm, N for No, or C to cancel." CHOICE /T 10 /C ync /CS /D y CHOICE /C ab /M "For option 1 please choose a, for option 2 please choose b." CHOICE /C ab /N /M "For option 1 please choose a, for option 2 please choose b." ==== Editor's note by willsort =============================== I am listing the help for choice under win98 here for distinction Waits for the user to choose one of a set of choices. Waits for the user to choose one from a group of selectable characters CHOICE choices] c,nn] /Cchoices Specifies allowable keys. Default is YN Specifies allowable keys (selectable characters), default is YN /N Do not display choices and ? at end of prompt string. Do not display the question mark and selectable characters in the prompt string /S Treat choice keys as case sensitive. Treat selectable characters as case-sensitive /Tc,nn Default choice to c after nn seconds Default to choice c after nn seconds text Prompt string to display Prompt string to display ERRORLEVEL is set to offset of key user presses in choices. ERRORLEVEL is set to the offset of the character the user presses within the set of choices If I run the command: CHOICE /C YNC /M "Press Y to confirm, N for No, or C to cancel." The screen will display: Press Y to confirm, N for No, or C to cancel. ? Example: the contents of test.bat are as follows (note: when using if errorlevel to judge return values, they should be arranged from high to low): @echo off choice /C dme /M "defrag,mem,end" if errorlevel 3 goto end if errorlevel 2 goto mem if errorlevel 1 goto defrag :defrag c:dosdefrag goto end :mem mem goto end :end echo good bye After this batch file runs, it will display "defrag,mem,end?" The user can choose d m e, and then the if statements make judgments according to the user's choice. d means execute the program segment with the label defrag, m means execute the program segment with the label mem, and e means execute the program segment with the label end. At the end of each program segment, goto end is used to jump the program to the end label, then the program displays good bye, and the batch file finishes running. 4. for loop command. As long as the condition is met, it will execute the same command many times. Syntax: Execute a specific command for each file in a set of files. FOR %%variable IN (set) DO command %%variable Specifies a single-letter replaceable parameter. (set) Specifies one file or a group of files. Wildcards can be used. command Specifies the command to execute for each file. command-parameters Specifies parameters or command-line switches for a specific command. For example, a batch file has a line: for %%c in (*.bat *.txt) do type %%c Then this command line will display the contents of all files in the current directory whose extensions are bat and txt. ==== Editor's note by willsort ===================================================== It should be pointed out that when the string inside () is not a single or multiple filenames, it is simply treated as a string substitution. This characteristic, together with the fact that multiple strings can be embedded in (), makes it obvious that for can be regarded as a traversal loop. Of course, in the command-line environment of the nt/2000/xp/2003 series, for has been given more features, enabling it to analyze command output or strings in files, and many switches are used to extend file substitution functions. ======================================================================== Batch file examples 1. IF-EXIST 1) First use Notepad to create a batch file test1.bat in C:, with the following content: @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 AUTOEXEC.BAT exists in C:, its contents will be displayed; if it does not exist, the batch file will tell you that the file does not exist. 2) Next create another file test2.bat with the following content: @ECHO OFF IF EXIST %1 TYPE %1 IF NOT EXIST %1 ECHO %1 does not exist Execute: C:>TEST2 AUTOEXEC.BAT The result of this command is the same as above. Explanation: (1) IF EXIST is used to test whether a file exists, in the format IF EXIST command (2) %1 in the file test2.bat is a parameter. DOS allows 9 pieces of batch parameter information to be passed to a batch file, namely %1~%9 (%0 represents the test2 command itself). This is a bit like the relationship between actual arguments and formal parameters in programming. %1 is the formal parameter, and AUTOEXEC.BAT is the actual parameter. ==== Editor's note by willsort ===================================================== DOS does not have a limitation of "allowing 9 pieces of batch parameter information" to be passed. The number of parameters is only limited by the command-line length and the processing ability of the called command. However, in a batch program, at the same moment we can only reference 10 parameters at the same time, because DOS only provides the ten parameter references %0~%9. ======================================================================== 3) Going one step further, create a file named TEST3.BAT with the following content: @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 display: XIAO TIAN XIN If you run: C:>TEST3 A B The screen will display XIAO TIAN During the execution of this command, DOS assigns an empty string to parameter %3. 2. IF-ERRORLEVEL Create TEST4.BAT with the following content: @ECHO OFF XCOPY C:AUTOEXEC.BAT D: IF ERRORLEVEL 1 ECHO File copy failed IF ERRORLEVEL 0 ECHO File copied successfully Then execute the file: C:>TEST4 If the file copy succeeds, the screen will display "File copied successfully"; otherwise it will display "File copy failed." IF ERRORLEVEL is used to test the return value of the previous DOS command. Note that it is only the return value of the immediately previous command, and the return values must be judged in descending order. Therefore the following batch file is wrong: @ECHO OFF XCOPY C:AUTOEXEC.BAT D: IF ERRORLEVEL 0 ECHO File copied successfully IF ERRORLEVEL 1 ECHO File to copy not found IF ERRORLEVEL 2 ECHO User aborted the copy operation with ctrl-c IF ERRORLEVEL 3 ECHO Initialization error prevented the file copy operation IF ERRORLEVEL 4 ECHO Disk write error during copy No matter whether the copy succeeds or fails, the following: File to copy not found User aborted the copy operation with ctrl-c Initialization error prevented the file copy operation Disk write error during copy will all be displayed. Below are the return values of several common commands and what they mean: backup 0 backup successful 1 backup file not found 2 file-sharing conflict prevented completion of backup 3 user aborted backup with ctrl-c 4 backup operation terminated due to a fatal error diskcomp 0 disks compared identical 1 disks compared different 2 user aborted compare operation with ctrl-c 3 compare operation terminated due to a fatal error 4 initialization error aborted compare diskcopy 0 disk copy operation successful 1 non-fatal disk read/write error 2 user ended copy operation with ctrl-c 3 disk copy aborted due to a fatal processing error 4 initialization error prevented copy operation format 0 format successful 3 user aborted format process with ctrl-c 4 format aborted due to a fatal processing error 5 at the prompt "proceed with format(y/n)?" the user entered n to end xcopy 0 files copied successfully 1 file to copy not found 2 user aborted copy operation with ctrl-c 4 initialization error prevented file copy operation 5 disk write error during copy chkdsk 0 no errors found 255 one or more errors found choice 0 user pressed ctrl+c/break 1 user pressed the first key 255 error condition detected in the command line other the position of the valid character the user pressed in the list defrag 0 compression of fragments successful 1 internal error occurred 2 there are no empty clusters on the disk. To run DEFRAG, there must be at least one empty cluster 3 user exited DEFRAG with Ctrl+C 4 general error occurred 5 DEFRAG encountered an error while reading a cluster 6 DEFRAG encountered an error while writing a cluster 7 space allocation error 8 memory error 9 not enough space to compress disk fragments deltree 0 successfully deleted a directory diskcomp 0 the two disks are identical 1 differences found 2 comparison terminated by CTRL+C 3 severe error occurred 4 initialization error occurred find 0 search successful and at least one matching string was found 1 search successful but no matching string was found 2 an error occurred during the search keyb 0 keyboard definition file loaded successfully 1 illegal keyboard code, character set, or syntax was used 2 keyboard definition file is bad or not found 4 error in communication between keyboard and monitor 5 requested character set not ready move 0 successfully moved the specified file 1 an error occurred msav /N 86 a virus was detected replace 0 REPLACE successfully replaced or added the file 1 MS-DOS version incompatible with REPLACE 2 REPLACE cannot find the source file 3 REPLACE cannot find the source path or target path 5 cannot access the file to be replaced 8 not enough memory to execute REPLACE 11 command-line syntax error restore 0 RESTORE successfully restored the file 1 RESTORE cannot find the file to restore 3 user pressed CTRL+C to terminate the restore process 4 RESTORE terminated due to an error scandisk 0 ScanDisk did not detect any errors on the drive it checked 1 ScanDisk could not run because the command-line syntax was incorrect 2 ScanDisk terminated unexpectedly because memory was exhausted or an internal error occurred 3 the user caused ScanDisk to quit midway 4 while performing a surface scan, the user decided to exit early 254 ScanDisk found disk faults and corrected them all 255 ScanDisk found disk faults, but could not correct them all setver 0 SETVER completed the task successfully 1 the user specified an invalid command switch 2 the user specified an illegal filename 3 not enough system memory to run the command 4 the user specified an illegal version number format 5 SETVER did not find the specified item in the version table 6 SETVER did not find the file SETVER.EXE 7 the user specified an illegal drive 8 the user specified too many command-line parameters 9 SETVER detected missing command-line parameters 10 while reading the SETVER.EXE file, SETVER detected an error 11 the SETVER.EXE file is damaged 12 the specified SETVER.EXE file does not support the version table 13 there is not enough space in the version table for the new item 14 while writing the SETVER.EXE file, SETVER detected an error ======================================================================== 3. IF STRING1 == STRING2 Create TEST5.BAT, with the following contents: @echo off IF "%1" == "A" FORMAT A: Execute: C:>TEST5 A Then the screen will show the content asking whether to format drive A:. Note: to prevent the parameter from being empty, the string is usually enclosed in double quotes (or other symbols; note that reserved symbols cannot be used). For example: if == or if %1*==A* 5. GOTO Create TEST6.BAT with the following contents: @ECHO OFF IF EXIST C:AUTOEXEC.BAT GOTO _COPY GOTO _DONE :_COPY COPY C:AUTOEXEC.BAT D: :_DONE Notes: (1) Before the label is the ASCII colon ":"; there cannot be a 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 labels up to eight characters long. When it cannot distinguish between two labels, it will jump to the nearest one. ==== Editor's note by willsort ===================================================== 1) a label is also called a tag (label) 2) a label cannot begin with most non-alphanumeric characters, while a filename can use many of them 3) when two labels cannot be distinguished, it will jump to the label located earlier in the file ======================================================================== 6. FOR Create C:TEST7.BAT with the following contents: @ECHO OFF FOR %%C IN (*.BAT *.TXT *.SYS) DO TYPE %%C Run: C:>TEST7 After execution, the screen will display the contents of all files in the root directory of drive C: whose extensions are BAT, TXT, and SYS (excluding hidden files). |
|
| Floor2 estar | Posted 2007-04-20 04:03 |
| 中级用户 Posts 103 Credits 346 | |
|
This kind of post is everywhere.
|
|
| Floor3 hulongzhuo | Posted 2007-04-20 04:25 |
| 中级用户 Posts 135 Credits 294 | |
|
Just what I needed,
thumbs up!! |
|
| Floor4 htysm | Posted 2007-04-20 04:38 |
| 高级用户 Posts 415 Credits 866 | |
|
You still need to post this kind of thread? Look how many there already are in the forum.
|
|
| Floor5 zxgui | Posted 2007-04-20 11:17 |
| 初级用户 Posts 13 Credits 38 | |
|
Some people do need it too
Hehe |
|
| Floor6 bw070 | Posted 2007-04-20 11:42 |
| 中级用户 Posts 137 Credits 292 | |
|
Although it's a repost, it's still useful for people who need it, and the summary is pretty good
|
|
| Floor7 menglongfc | Posted 2007-04-22 00:16 |
| 初级用户 Posts 25 Credits 45 | |
|
An old thread
but a good one praise for you |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |