SoFunction
Updated on 2025-04-13

Batch BAT Enhanced Function Code Instructions Page 2/3


path: indicates the search path of the executable program. My suggestion is that you copy your program to
%windir%\system32\. This directory can usually be automatically searched.
Syntax: copy %windir%\system32\.
Use point (.) for easy viewing
Use double quotes for environment variables (English pattern, half-width)
%windir% variable
%%windir%% Quadratic variable reference.
We also use it often
%temp% Temp file directory
%windir% System Directory
%errorlevel% Exit code

The output file is to the temporary file directory. This makes the current directory cleaner.

For parameters with spaces. You should learn to use double quotes ("") to indicate such as operation on porgram file folders
C:\>dir p*
C:\ directory
2000-09-02 11:47 2,164
1999-01-03 00:47 <DIR> Program Files
1 file 2,164 bytes
1 directory 1,505,997,824 available bytes

C:\>cd pro*
C:\Program Files>

C:\>
C:\>cd "Program Files"
C:\Program Files>


######################################################################
3. Built-in special symbols (be careful to avoid them during actual use)
######################################################################
Microsoft has built-in characters that cannot be used in the file name created.
con nul aux \ / │ ││ && ^ > < *

You can use most characters as variable values, including white space. If you use the special characters <, >, │, &, or ^, you must precede them with the escape character (^) or quotation marks. If you use quotation marks, they are included as part of the value because everything following the equal sign is taken as the value. Consider the following examples:
(Summary: Either you use ^ as the leading character. Or you can only use double quotes "")
To create the variable value new&name, type:
set varname=new^&name

To create the variable value "new&name", type:
set varname="new&name"

The ampersand (&), pipe (│), and parentheses ( ) are special characters that must be preceded by the escape character (^) or quotation marks when you pass them as arguments.

find "Pacific Rim" < >
IF EXIST filename. (del filename.) ELSE echo filename. missing

> Create a file
>> Append to a file
@ prefix character. It means that this line is not displayed in cmd during execution. You can use echo off to close the display.
^ Leading characters for special symbols ( > < &). The first one just shows aaa and the second output file bbb
echo 123456 ^> aaa
echo 1231231 > bbb
() contains commands
(echo aa & echo bb)
, the default separator symbol like spaces.
; Comment, means that the comment is followed
: function of labeling
│ Pipeline Operation
& Usage: First Command & Second Command [& Third Command...]
This method can execute multiple commands at the same time regardless of whether the command is successfully executed.
dir c:\*.exe & dir d:\*.exe & dir e:\*.exe
&& Usage: First command && Second command [&& Third command...]
When an error occurs, the subsequent command will not be executed. If there is no error, all commands will be executed;
││ Usage: First command ││ Second command [││ Third command...]
When you encounter the correct command, the following command will not be executed. If no correct command appears, all commands will be executed all the time;

Common syntax formats
IF [NOT] ERRORLEVEL number command para1 para2
IF [NOT] string1==string2 command para1 para2
IF [NOT] EXIST filename command para1 para2

IF EXIST filename command para1 para2
IF NOT EXIST filename command para1 para2
IF "%1"=="" goto END
IF "%1"=="net" goto NET
IF NOT "%2"=="net" goto OTHER
IF ERRORLEVEL 1 command para1 para2
IF NOT ERRORLEVEL 1 command para1 para2
FOR /L %%i IN (start,step,end) DO command [command-parameters] %%i
FOR /F "eol=; tokens=2,3* delims=, " %i in () do echo %i %j %k
Take parameters in alphabetical order ijklmnopq.
eol=c - refers to the end of a line comment character (just one)
skip=n - refers to the number of lines ignored at the beginning of the file.
delims=xxx - refers to the separator set. This replaces the default separator set for spaces and jump keys.

Previous page123Next pageRead the full text