


以上内容保存为clean180log.bat.然后创建任务计划每天定时运行bat,即可@echo off
setlocal enabledelayedexpansion
REM 在下面添加内容: call:del180 文件夹路径
REM 比如dao删除”C:\Windows\System32\LogFiles\HTTPERR”和”D:\w3log\W3SVC10186″里修改时间在180天之前的文件
call:del180 “C:\Windows\System32\LogFiles\HTTPERR”
call:del180 “D:\w3log\W3SVC10186”
pause>con
goto :eof
:del180
call:getdate date
call:date2day date
pushd “%~1”
if /i not “!cd!”==”%~f1” exit /b 1
for /f “delims=” %%i in (‘dir /a:-d /b’) do (
set “datei=%%~ti”
call:getdate datei
call:date2day datei
set /a “date180=!date.num!-180”
if !datei.num! lss !date180! del /f “%%i”
)
exit /b 0
:date2day
set /a “%~1.num=0”
set /a “%~1.num+=(!%~1.y!-1)*365+(!%~1.y!-1)/4-(!%~1.y!-1)/100+(!%~1.y!-1)/400”
set /a “d=28+^!(!%~1.y!%%4)-^!(!%~1.y!%%100)+^!(!%~1.y!%%400)”
set /a “m=0”
for %%i in (31 !d! 31 30 31 30 31 31 30 31 30 31) do (
set /a “m+=1”
if !%~1.m! gtr !m! set /a “%~1.num+=%%i”
)
set /a “%~1.num+=!%~1.d!”
exit /b
:getdate
set “%~1.y=!%~1:~0,4!”
set “%~1.m=!%~1:~5,2!”
set “%~1.d=!%~1:~8,2!”
set /a “%~1.y=10000!%~1.y!%%10000”
set /a “%~1.m=10000!%~1.m!%%10000”
set /a “%~1.d=10000!%~1.d!%%10000”
exit /b



文章评论 本文章有个评论