rem do not show instructions@echo off
rem echo the following sentence (do not need quotation marks)echo This is the first line of the program.
rem set variables and call variablessetlayout=Hello, world!
echo%layout%rem /A means Arithmeticset/Afirst=10set/Asecond=20set/Aadd=%first%+%second%echo sum is %add%rem set global and local variablesset/AglobalVariable=1SETLOCALset/AlocalVariable=%glabalVariable%+2echo Global variable is %globalVariable%echo Local variable is %localVariable%ENDLOCAL
@echo off
rem judge whether a variable is emptyseta=Hi, world
setz=if [%a%]==[] echo a is empty!
if [%z%]==[] echo z is empty!
rem Substring: <string>:~<begin>[,length]setstr=HiAbies
echo.%str%setstr=%str:~0,2%echo.%str%rem Replace: <string>:<old>=<new>setstr=Hi, my name is abies
setstr=%str:abies=Abies%echo.%str%
@echo off
rem /l means looprem %%i means i is a loop variablefor/l%%i in(1,1,10)do(echo step %%i
)rem traverse a specific list, can not use /lsetmyArray=1 2 4 5 6
for%%i in(%myArray%)do(echo step %%i
)rem while looprem call is used to handle nested expansionsetlocal enabledelayedexpansion
setmyArr[0]=1
setmyArr[1]=7
setmyArr[2]=13
seti=0
:myloopifdefinedmyArr[!i!](settmp=myArr[!i!]
echo Element !i! = !tmp!set/a"i+=1"GOTO:myloop)
@echo off
rem input text into fileecho hold me in the darkness > temp.txt
rem echo contents of folerem /f means file, "tokens=*" means read the whole linefor/f"tokens=*"%%x in(temp.txt)do(echo%%x)
@echo off
setlocal enabledelayedexpansion
setcount=1000
:: start from 1001, thus the last 3 bits starting from 001for%%f in(*.jpg)do(set/acount+=1ren"%%f""Fig_!count:~-3!.jpg")echo Finish!
pause