windows批处理备份压缩文件夹rar
由于工作需要简单研究了下批处理打压缩包,根据修改时间打包当天的,如果要copy文件夹为空时会创建新的,如果当前目录下有改批处理文件会排除
直接上代码,yasuo_ok.bat
// 可在此基础上完善一下
echo off
color 2F
set currenttime=%date:~0,4%%date:~5,2%%date:~8,2%
rem echo %currenttime%
rem from 源文件夹位置;
rem to 目标文件夹位置;
rem rar 压缩软件安装路径
rem batName 压缩文字名称全称带扩展名
rem suffix 文件夹后缀
set from=e:\testImg\
set to=d:\哈哈哈\
set rar=c:\Program Files\WinRAR\WinRAR.exe
set batName=yasuo_ok.bat
set suffix=_hpdl
set enter=%from:~0,2%
%enter%
cd %from%
setlocal enabledelayedexpansion
rem echo !currenttime!
for /f "delims=" %%i in ('dir /b "%from%"') do (
set getTime=%%~ti
set needTime=!getTime:~0,4!!getTime:~5,2!!getTime:~8,2!
rem echo %%i
rem 判断当天时间与获取的修改时间是否相同,相同则拷贝到新建的文件夹中以供压缩使用
if !currenttime! equ !needTime! ( if %%i neq %batName% md "%to%%currenttime%%suffix%\%%i"&xcopy /e/i "%from%%%i" "%to%%currenttime%%suffix%\%%i" /y/d )
)
rem 压缩文件当天时间命名
if exist "%to%%currenttime%%suffix%" (
"%rar%" a -ep1 "%to%%currenttime%%suffix%.rar" "%to%%currenttime%%suffix%"
)
rem 删除临时文件夹
if exist "%to%%currenttime%%suffix%" (
rd /s/q "%to%%currenttime%%suffix%"
)
rem pause
exit