批处理(Batch)脚本常用汇总2022-10-10_批处理文件执行cmd命令

2023-03-26 21:56:00

 

1.批处理脚本实例

批处理(Batch),也称为批处理脚本顾名思义,批处理脚本是一种脚本语言,应用于DOS和Windows系统中,用于对某对象进行批量的处理包含批处理脚本的文件是批处理文件,批处理文件(.bat文件)是可执行文件,由一系列cmd命令构成。

2.批处理脚本编写教程

----------------------------------------------------------------------------------------------------------------

3.bat批处理脚本

一、工作中批处理总结:1.批量删除某一目录下的文件,该文件类型为.log文件@echooffREMzaaREM1.0.0REM文件复制批处理脚本REM1.源文件夹setprimitive="E:\Folders\01_工作记录\08_时间轴记录\2022\20220831-杭海线-运维故障排查\TRAIN-1,TC1\Train-1-log"。

4.批处理文件(.bat)怎么写?

echo正在清除log文件,请稍等......pause::删除当前路径下log文件addbyzaa2022-9-03beginREM3.循环删除del/f/s/q%primitive%\*.log::

5.windows常用批处理脚本

删除当前路径下log文件addbyzaa2022-9-03endecho清除log文件完成!echo.&pause2.批量拷贝某一个目录下的文件,该文件类型为.log文件,拷贝到另外一个指定目录@echo。

6.批处理.bat

offREMzaaREM1.0.0REM文件复制批处理脚本REM1.源文件夹setprimitive="E:\Folders\01_工作记录\08_时间轴记录\2022\20220831-杭海线-运维故障排查\TRAIN-1,TC1\TRAIN-1,TC1"

7.批处理文件命令大全

REM2.目的文件夹setdestination="E:\Folders\01_工作记录\08_时间轴记录\2022\20220831-杭海线-运维故障排查\TRAIN-1,TC1\Train-1-log"

8.批处理文件是脚本吗

echo正在拷贝日志文件,请稍等......pauseREM3.循环打印for/R%primitive%%%iin(*.log)doecho%%ipauseREM4.循环复制for/R%primitive

9.bat批处理命令大全

%%%fin(*.log)docopy/y"%%f"%destination%echo正在拷贝日志文件完成!echo.&pause3.定时关机程序,倒计时5秒@echooffREMzaaREM1.0.0

10.批处理脚本入门

REM文件复制批处理脚本REM1.设置定时关机时间setcounting_time=5echo正在关机,请稍等......倒计时%counting_time%秒...pauseshutdown-s-t%

counting_time%4.批量修改一个目录下的文件的文件名,该文件原来的类型为.log文件,修改成.txt文件@echooffREMzaaREM1.0.0REM重命名文件,批处理脚本REM1.源文件夹

setprimitive="E:\Folders\01_工作记录\08_时间轴记录\2022\20220907-长沙线-运维故障排查\pcapng"echo正在重命名文件,请稍等......pauseREM

2.循环打印for/R%primitive%%%iin(*.log)doecho%%ipauseREM3.先删除已经重命名过的文件,然后再重命名for/R%primitive%%%fin(*.txt)do

del/f/s/q"%%f"pauseREM4.循环重命名for/R%primitive%%%fin(*.log)doren"%%f"*.txtecho重命名文件完成!echo.&pause5.批量修改一个目录下的文件的文件名,该文件原来的类型为.log文件。

将所有文件名中"dcs"改为"supervision"@echooffREMzaaREM1.0.0REM重命名文件,批处理脚本setlocalEnableDelayedExpansioncolor0aecho

%data%%time%echorenamefilenow...seta=1pausefor/f%%iin(dir/b*.log)do(set"str=%%~nxi"REM这里~表示从第几位开始截取名称

,~3表示从第三位开始截取,~3,7表示从第三位截取到第七位set"shortstr=!str:~3!"REM这里是将"-"换成了"_"set"replacestr=!shortstr:-=_!"echo

!replacestr!ren"%%i"supervision!replacestr!set/aa=a+1))set/aa=a-1echorenamefinish,renamecount:%a%echo。

.&pause6.批量修改一个目录下的文件的文件名,该文件原来的类型为.log文件将所有文件名中"dcs"改为"supervision"@echooffREMzaaREM1.0.0REM重命名文件,批处理脚本

color0aecho%data%%time%echorenamefilenow...seta=1pausesetlocalEnableDelayedExpansionfor/f%%iin(dir/b*

.log)do(set"str=%%~nxi"REM这里是直接将"dcs"换成了"supervision"set"replacestr=!str:dcs=supervision!"echo!replacestr

!ren"%%i"!replacestr!set/aa=a+1))endlocalset/aa=a-1echorenamefinish,renamecount:%a%echo.&pause7.给系统添加java环境变量,java的安装路径为:"D:\Program Files\Java\jdk1.8.0_152"。

@echooffREMzaaREM1.0.0@echo以管理员身份运行,否则会拒绝访问系统变量setlocalEnableDelayedExpansioncolor0asetjava_home="D:\Program Files\Java\jdk1.8.0_152"

echo%data%%time%pausecall:addpath!java_home!gotoend:addpathsetx/MJAVA_HOME%1setx/MCLASSPATH".;%%JAVA_HOME%%\lib;%%JAVA_HOME%%\lib\tools.jar;"

setx/MPATH"%PATH%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin;"goto:eof:end8.批处理脚本,批量修改文件名称@echooffREMzaa。

REM1.0.0REM重命名文件,批处理脚本setlocalEnableDelayedExpansioncolor0asetLowerCase=supervisionsetUpperCase=SUPERVISION

echo%data%%time%echorenamefilenow...seta=1pausefor/f%%fin(dir/b*.log)do(REM这里是直接将"LowerCase"换成了"UpperCase"

setstring=%%fsetfrom=!LowerCase!setto=!UpperCase!call:convert!from!!to!move%%f!string!set/aa=a+1)set/

aa=a-1echorenamefinish,renamecount:%a%endlocalecho.&pausegotoend:convertsetstring=!string:%1=%2!goto:

eof:end9.在文件名称后面增加序列号,从266开始@echooffREMzaaREM1.0.0REM重命名文件,批处理脚朿color0aecho%data%%time%echodealfilenow

...setlocalEnableDelayedExpansionseta=1setfilenum=266pausefor/f%%iin(dir/b*.jpg)do(REM获取文件名,不包含后缀setname

=%%~niREM获取文件后缀,不包含文件吿setext=%%~xisetext=!ext:~1!REM修改文件名,加上序号setreplacestr=!name!_!filenum!echofrom!

name!.!ext!to!replacestr!.!ext!move!name!.!ext!!replacestr!.!ext!set/afilenum=filenum+1set/aa=a+1))set

/aa=a-1echodealfinish,dealcount:%a%endlocalecho.&pause10.在文件名称格式化,格式化为三位数字,不足补0@echooffREMzaaREM1.0.0。

REM重命名文件,批处理脚朿color0aecho%data%%time%echodealfilenow...setlocalEnableDelayedExpansionseta=1pausefor/f

%%iin(dir/b*.jpg)do(REM获取文件名,不包含后缀setname=%%~niREM获取文件后缀,不包含文件吿setext=%%~xisetext=!ext:~1!REM修改文件名,加上序号

Set"seq=000!name!"&Set"seq=!seq:~-3!"setreplacestr=!seq!echofrom!name!.!ext!to!replacestr!.!ext!move!

name!.!ext!!replacestr!.!ext!set/aa=a+1))set/aa=a-1echodealfinish,dealcount:%a%endlocalecho.&pause11.去掉文件名中的特殊字符。

@echooffREMzaaREM1.0.0REM重命名文件,批处理脚朿color0aecho%data%%time%echodealfilenow...setlocalEnableDelayedExpansion

seta=2setseq=266pausefor/f%%iin(dir/b*.jpg)do(REM获取文件名,不包含后缀setname=%%~niREM获取文件后缀,不包含文件吿setext=%%~xi

setext=!ext:~1!Set"replacestr=!name:20221201101420201jpg_Page=!"&Set"replacestr=!replacestr:_Image1=!"

REM修改文件名,加上序号REMsetreplacestr=!name!_!filenum!echofrom!name!.!ext!to!replacestr!.!ext!,seq=!seq!move!

name!.!ext!!replacestr!.!ext!set/aa=a+1set/aseq=seq+1))set/aa=a-1echodealfinish,dealcount:%a%endlocal

echo.&pause----------------------------------------------------------------------------------------The batch file scripts which is,in the windows system,operated through administrator role consists of very commands towards unique function......

 


以上就是关于《批处理(Batch)脚本常用汇总2022-10-10_批处理文件执行cmd命令》的全部内容,本文网址:https://www.7ca.cn/baike/8482.shtml,如对您有帮助可以分享给好友,谢谢。
声明

排行榜