@echo off
::color 1
rem echo usege
echo hello word!
echo.off
echo.
echo.on
rem set 用法
set ver=abc
echo %ver%
::reset the ver
set ver=
set ver_1=def
set ver_2=%ver%
echo %ver_1%
::set /a 数值表达式
set /a a1=1,a2=2
set /a res=a1 + a2
echo res=%res%
set /a result=%res%
echo result=%a1%+%a2%=%result%
if %a1%==%a2% (
echo a1 is equal to a2
) else (
echo a1 is not equal to a2
)
if %errorlevel%==0 (
echo success!
) else (
echo failed!
)
if errorlevel 1 (
echo success 1 !
) else (
echo failed 1 !
)
if exist C:\meng_F\DOCmdStudy\test.txt (
echo file is find
del C:\meng_F\DOCmdStudy\test.txt
) else (
echo file is not find !
)
if defined a1 (
echo a1 have define
) else (
echo a1 no define
)
::set /p 变量名=值 等号不要加空格
::set /p info=input:
::echo your input info : %info%
::/I distinguish the A and a
set test1=123
set test2=abc
set test3=12
if /I %test2% equ ABC (
if %test1% geq %test3% (
echo %test1%^>=%test3%
) else (
echo test1^<test3
)
) else (
echo %test2% not equal ABC!
)
::set local enableDelayExpansion
echo eg_1
set local_test=apple
if %local_test%==apple (
set local_test=orange
if %local_test%==orange (
echo reset veriable successful [%local_test%]
) else (
echo reset veriable failed [%local_test%]
)
)
echo %local_test%
echo eg_2
setlocal enableDelayedExpansion
set local_test_1=apple1
if %local_test_1%==apple1 (
set local_test_1=orange1
if "!local_test_1!" == "orange1" (
echo reset successful [!local_test_1!]
) else (
echo reset failed [!local_test_1!]
)
)
echo %local_test_1%
endlocal
::for
echo eg_1
for %%i in (1,3,5,7) do echo %%i
echo eg_2
for %%i in (1,*) do (
echo %%i
)
echo eg_3
cd C:\meng_F\DOCmdStudy
echo file:
for %%f in (*) do (
echo %%f
)
echo folder:
for /d %%d in (*) do (
echo %%d
)
echo eg_4
echo file:
for /r C:\meng_F\DOCmdStudy %%f in (*) do (
echo %%f
)
echo folder:
for /d /r C:\meng_F\DOCmdStudy %%d in (*) do (
echo %%d
)
echo 1
goto a
echo
:a
echo 2
:b
echo 3
goto end
:end
echo 4
pause
@echo off
rem goto 语句练习,根据输入内容跳转到不同的标记位置
:start
set /p num1=one:
set /p num2=two:
set /p op=1.add 2.sub 3.mul 4.div
if %op% == 1 goto add
if %op% == 2 goto sub
if %op% == 3 goto mul
if %op% == 4 goto div
if %op% == "" goto :eof
:add
set /a result=%num1%+%num2%
echo %num1%+%num2%=%result%
goto end
:sub
set /a result=%num1%-%num2%
echo %num1%-%num2%=%result%
goto end
:mul
set /a result=%num1%*%num2%
echo %num1%*%num2%=%result%
goto end
:div
set /a result=%num1%/%num2%
echo %num1%/%num2%=%result%
goto end
:end
set /p choose=exit? (Y/N):
if /i %choose% equ y (
exit
) else (
goto start
)
rem 设置标题的内容
title nick test
pause > nul
.bat 文件dos comand 批处理学习
本文详细介绍了DOS命令的使用,包括变量设置、条件判断、循环控制以及文件操作等,还展示了批处理脚本的编写技巧,如延迟变量扩展和局部变量的管理。此外,还通过实际示例演示了如何处理算术运算和文件查找。最后,通过用户输入引导实现简单的计算操作,并展示了错误处理和程序流程控制。
摘要由CSDN通过智能技术生成