常用批处理

@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


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    
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

你可能感兴趣的:(常用批处理)