批处理学习01

《批处理在提高Windows管理效率中神奇应用》学习

::1.3
::echo. 显示空行
::数值范围循环的for循环
@echo off
echo Creating file0.txt ~ file99.txt
echo.
echo.
:: for /l %%n in (0,1,99) /l表示for语句在指定的数值范围内循环。范围由in决定
::in (0,1,99) 表示从0开始,步长为1,到99结束(包含99)
for /l %%n in (0,1,99) do (
echo %%n >> file%%n.txt
)
echo File created.
pause
::1.4
::数值弄变量
::for循环处理文件。
::删除变量,以免影响系统或其他批处理。
@echo off
echo Begin to change file name
set ex=.rar
set /a sum=0
::当前目录下的每一个文件
for %%m in (*) do (
::字符串判断,其实有更好的写法。
::%0就是当前文件的文件名的字符串
::if not "%%m"==%0 (
::这种尝试是失败的
if not "%%m"=="1.4.bat" (
ren %%m %%m%ex%
::将sumw值加1
set /a sum=sum+1
)
)
echo There are total %sum% files` name changed
::删除变量,以免影响系统或其他批处理。
set sum=
set ex=
pause
::1.5
::关于当前文件,当前文件名,
@echo off
echo 当前文件名%0
echo 当前文件名%~n0
echo 本文件所在路径%~dp0
echo 初始工作路径%cd%
cd d:
echo 改变后的工作路径%cd%
pause
原文地址:https://www.cnblogs.com/itit/p/3726899.html