常用批处理

该批处理脚本主要执行了如下操作:设置颜色,获取当前目录,查找字符串,进行VisualStudio的编译清理工作,处理时间格式,创建和删除目录,以及文件操作。此外,还包含了一个计算时间差的函数和遍历目录及文件的辅助函数。
摘要由CSDN通过智能技术生成
@ECHO OFF
CLS
rem "Color 0是黑色 a是绿色 https://blog.csdn.net/m0_60277871/article/details/121280231"
color 0a
setlocal enabledelayedexpansion

rem RootPath为当前批处理目录
set RootPath=%~dp0
echo %RootPath%

rem 查找字符串
set str="123456"
echo %str%|findstr "456" > nul
if %errorlevel% equ 0 (
echo ok
) else (
echo not ok
)

rem vs编译
set CABWIZ=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE
cd /d %CABWIZ%
rem devenv %PATH%test.sln /Clean "Release|X64"
rem devenv %PATH%test.sln /Clean "Release|X86"
rem devenv %PATH%test.sln /build "Release|X64"
rem devenv %PATH%test.sln /build "Release|X86"
rem devenv %PATH%test.sln /rebuild "Release|X86"
rem devenv %PATH%test.sln /project "Tool" /build "Release|X64"

rem 有个问题, 就是如果TIME 是00点的时候,电脑显示的是0 不是00所以TIME 0~2 会有空格。 解决方案 补0
if %time:~0,2% leq 9 (set hour=0%time:~1,1%) else (set hour=%time:~0,2%)
set DATE=%date:~0,10%
set FILENAME=Test_%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%_%hour%%time:~3,2%%time:~6,2%.zip
echo %FILENAME%

if not exist %RootPath%log1 (
echo "%RootPath%log1 文件夹不存在"
)
if exist %RootPath%log (
echo "%RootPath%log 文件夹存在"
)
if exist %RootPath%网卡信息.txt (
echo "%RootPath%网卡信息.txt 文件存在"
)
rem 计算两个时间的差
call :ctime 23:00:00.00 %time% t
echo  %t%



rem 创建目录
md %RootPath%dir

rem 删除目录
rd /s /q %RootPath%dir

rem 删除文件 
rem del /s /q %RootPath%\old.dll
/S 从所有子目录删除指定文件
/Q 安静模式。删除全局通配符时,不要求确认
/F 强制删除只读文件


rem 拷贝文件
rem copy /Y  %RootPath%Test\1.exe  %OUTPUT%\x64
rem copy /Y %RootPath%Test\*.*  %OUTPUT%\x64\tap6

rem 拷贝文件夹
rem xcopy %RootPath%\Resources %OUTPUT%\x64\tap6

rem 7z压缩
rem C:\7z\7z.exe a %PATH%%FILENAME% %OUTPUT%

rem 调用函数
call :listFile %RootPath%log
call :listDir %RootPath%log
pause
goto :eof

rem 遍历文件
:listFile
for %%i in (%1\*) do (
echo "File [%%i]"
)
goto :eof

:listDir
rem 遍历文件夹
for /d %%i in (%1\*) do (
echo "dir [%%i]"
rem 递归调用函数
call :listFile %%i
)
goto :eof


:ctime <begin_time> <end_time> <return> 
rem 无论传入是否带毫秒将忽略它
rem 返回时间为24h以内尾数(即相差是整天数),为hh:mm:ss格式 
setlocal
for /f "tokens=1-6 delims=:" %%a in ("%1:%2")do (
  set/a "sh=100+%%d-%%a,sm=2%%e-1%%b,ss=2%%~nf-1%%~nc")
if %ss% lss 100 set/a ss+=60,sm-=1
if %sm% lss 100 set/a sm+=60,sh-=1
if %sh% lss 100 set/a sh+=24
endlocal&set %3=%sh:~-2%:%sm:~-2%:%ss:~-2%
goto :eof
@ECHO OFF
CLS
color 0a
setlocal enabledelayedexpansion

set DstDir=C:\Program Files\Work\bin
set RootPath=%~dp0
echo %RootPath%

call :copyFile Drv.sys Drv_bk.sys
call :copyFile NetDrv.sys NetDrv_bk.sys
call :copyFile guardx.dll guardx_bk.dll
call :copyFile Dll.dll  Dll_bk.dll
call :copyFile control.dll control_bk.dll
call :copyFile Svc.exe Svc_bk.exe
call :copyFile32 guardx.dll guardx_bk.dll
call :copyFile32 Dll.dll Dll_bk.dll
call :copyFile32 control.dll control_bk.dll
call :copyFile32 Svc.exe Svc_bk.exe

shutdown -r -t 0
pause

:copyFile
if exist "%RootPath%%1" (
del /q "%DstDir%\%2"
rename "%DstDir%\%1" "%2"
copy /Y "%RootPath%%1"  "%DstDir%\%1"
del /q "%RootPath%%1"
echo copyFileEnd: "%RootPath%%1"
)
goto :eof

:copyFile32
if exist "%RootPath%32\%1" (
del /q "%DstDir%\32\%2"
rename "%DstDir%\32\%1" "%2"
copy /Y "%RootPath%32\%1"  "%DstDir%\32\%1"
del /s /q "%RootPath%32\%1"
echo copyFile32End: "%DstDir%\32\%2"
)
goto :eof

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值