windows批处理备份压缩文件夹rar

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值