备份指定目录日期为最新的文件

备份指定目录日期为最新的文件

 

@echo off
rem 先要检查 echo %date:~0,10% 的输出内容,不能含斜划线。

set sdir=
set sfiletype=*
set ddir=
set tfile=

rem for /f %%a in (dir /b /o:-d %sdir%\*.%sfiletype%) do 7za.exe a %ddir%\%%a %sdir%

rem 仅取第一个文件名
rem del /q /f "%temp%\%tfile%"
rem dir /b /o:-d %sdir%\*.%sfiletype% > "%temp%\%tfile%"
rem set /p newfile=<"%temp%\%tfile%"
rem 7za.exe a %ddir%\%newfile%.7z %sdir%\%newfile%

rem 一个文件一个包(无子目录)
forfiles /p %sdir% /m *.%sfiletype% /d +%date:~0,10% /c "cmd /c 7za.exe a %ddir%\@file.7z @path"

rem 所有文件一个包
del /q /f %tfile%
forfiles /p %sdir% /m *.%sfiletype% /d +%date:~0,10% /c "cmd /c echo @path >> %tfile%"
7za.exe a -t7z %date:~0,10%.7z @%tfile%


forfiles /p "%ddir%" /m *.7z /s /d -10 /c "cmd /c del /q /f @path"

rem 删除空目录
dir /ad /b /s %ddir%|sort /r > %tfile%
for /f %%a in (%tfile%) do rd %%a

del /q /f %tfile%
exit

 

转载于:https://www.cnblogs.com/Tty725/p/4523382.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值