@ Echo off
Rem checks whether a file exists
If exist example.txt echo found it
The REM command combination is similar to the short path operation of Js.
Dir example.txt & Echo found it too
Rem Append content everywhere to files
ECHO not bad day> exmple.txt
The simplest combination of REM commands
Echo Hello & Echo world!
Rem, This is a comment, to make the Earth understand
Echo comments example
Rem | (the output of the previous command serves as the input of the next command) More one screen displays the following content: Enter 1 line, space 1 screen
: Help | more
: More longarticle.txt
: Type longarticle.txt
Rem | for short path operations, refer to JS
Dir setup _ *. exe | ECHO can see me
Dir Foo. TTT & dir foo.txt | ECHO can not see me 2
Dir Foo. TTT & dir foo.txt | ECHO can see me 2
Rem input redirection <> & <&
: More <longarticle.txt
Rem output redirection >>>
: ECHO has some good idea> haha.txt
: Echo come on> haha.txt
The REM call command calls the other batch from one batch and accepts the input parameters.
Call hi. Bat Sindy
: Hi. bat
: Echo hello, % 1
The REM choice command prompts the user to enter a letter to select it. The return code is 1234 ......
Choice/c abc/M apple, banana, coffee
If errorlevel 3 goto coffee
If errorlevel 2 goto banana
If errorlevel 1 goto Apple
: Apple
Echo you like apple
Goto end
: Banana
Echo you like banana
Goto end
: Apple
Echo you like coffee
Goto end
: End
Echo goodbye
Rem find command find string note that this string requires double quotation marks
Netstat-An> a.txt
Type. txt | find "5355" & Echo Yes, you found the string
Rem if command to determine input parameters
If "% 1" = "" Goto usage
If "% 1" = "/? "Goto usage
If "% 1" = "help" Goto usage
: If not "% 1" = "" Goto somejob
: Usage
Echo this is something about how to use bat
Rem checks whether a file exists
If exist *. jpg del *. jpg
: If not exist *. jpg mkdir PIC
: The DOS program has a return code after running). If the returned code matches the defined error code (the error code defined here is 1 ), then execute the corresponding operation (here the corresponding operation is pause & edit % 1. ASM part)
: MASM % 1.asm
: If not errorlevel 1 link % 1.obj
: Pause & edit % 1.asm
::------------------------
: MASM % 1.asm
: If exist % 1.obj link % 1.obj
: Else pause & edit % 1.asm
Rem if [not] errorlevel number do command
Rem if [not] string1 = string2 do command
Rem if [not] exist filename do command
Batch Processing tutorial