Note: Must be saved in ASCII format and the file name cannot contain Chinese
Basic command:
@echo off
echo means maneuver, and here's what it means, echo off, which means to turn off echoing. The previous @ means Echooff this line will not echo you can try to get rid of the @ and the whole line. Another feature of @ is that the command echo is automatically restored when the batch file is finished executing.
Test:
@echo off
Ipconfig
Pause
Pauses execution of the batch program and displays a message prompting the user to press any key to continue execution.
REM
Comment Instructions
Pager
Invoke directives
Example 1:
Write a test.bat and put it on the C drive.
@echo off
Echo%1 – Here%1 is the input parameter, ECHO is the output display
Then open cmd, enter call C:\test.bat "Dingxiaowei", will display "Dingxiaowei"
Example 2:
The above Test.bat changed to
Ping%1
Ping%2
Effect:
if
Judgment instruction
Three different ways:
IF [not]string1==string2 command
IF [not]exist filename command
IF [not]errorlevel number command
Example 1:
@echo off
If%1 = = 1 echo "a = 1"
Example 2:
Detect if a file exists
@echo off
If Existe:1.txt echo "exist 1.txt"
Goto
Jump Execution Instructions
@echo off
NET user
If%errorlevel% = = 0 Goto successed
if%errorlevel% = = 1 goto failed
: successed
echo Netuser executed successfully!
Goto return
: Failed
Echo Netuser failed to execute!
: Return
Set
Set command
For parameter percent variable name in (related file or command) do command
Parameters: For has 4 parameters/d/l/r/f
Example:
Set protogen= "%~dp0....\tools\release\protobuf\protogx\protogx.exe"
%~dp0\ indicates the current path
/d is directory only
@echo off
FOR/D%%i in (*) do @echo%%i
Pause
Save him in the C-packing directory to execute, will be the C-disk directory of all the directory name printed out
@echo off
FOR/D%%i in (???) Do @echo%%i
Pause
The current directory has a directory name of only 1-3 letters, it will be displayed, no, not show
echo off
FOR/D%%i in (e:*) do echo%%i
This command scans only the subdirectory names of the current directory, and does not scan subdirectories that are contained in subdirectories
/R recursion
@echo off
FOR/R c \%%i in (*.exe) do @echo%%i
Pause
Search for all EXE files
FOR/R c:\%%i in (.) Do echo%%i
Scan out the names of all subdirectories under the current directory, recursively traverse
/F for traversing files
for/f%%i in (a.txt) do echo%%i
Will read out the contents of the a.txt, if not/F will only display the file name
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Windows Batch Processing