注意7zip安装目录中不要包含空格
注意today的日期格式是否与当前系统匹配
@echo off
rem 7zip路径
set zipSoft="C:\7-Zip\7z.exe"
rem 压缩文件路径
set filePath="D:\temp\test"
rem 今天日期
set today=%date:~0,4%-%date:~5,2%-%date:~8,2%
rem 压缩多少天前的文件
set delDays=7
forfiles -p %filePath% /m *.csv /d -%delDays% /c "cmd /C echo @file" > %filePath%\%today%-bat.log
forfiles -p %filePath% /m *.csv /d -%delDays% /c "cmd /C %zipSoft% a %filePath%\%today%.7z @file "
forfiles -p %filePath% /m *.csv /d -%delDays% /c "cmd /C del @path" >> %filePath%\%today%-bat.log
echo finish >>%filePath%\%today%-bat.log
网友评论