bat 比较文件修改时间和当前系统时间,如果文件修改时间小于系统时间5分钟就输出一条告警到文本
在其他帖子中看到了这个回帖,但是发现一个问题,就是系统时间小时位小于10的时候,算法有问题,不能准确判断,好像是05:05和5:05是两个数值。请大神帮忙修改一下,谢谢!...
在其他帖子中看到了这个回帖,但是发现一个问题,就是系统时间小时位小于10的时候,算法有问题,不能准确判断,好像是05:05和5:05是两个数值。请大神帮忙修改一下,谢谢!
@echo off&setlocal enabledelayedexpansion
set "fn=e:\a.txt"
:loop
for %%a in ("%fn%") do (
if exist "%fn%" (
for /f "tokens=1-10 delims=/-: " %%i in ("%%~ta !date:~,10! !time:~,5!") do (
set/a y1=%%i,m1=1%%j%%100,d1=1%%k%%100,h1=1%%l%%100,f1=1%%m%%100,y2=%%n,m2=1%%o%%100,d2=1%%p%%100,h2=1%%q%
%100,f2=1%%r%%100
set /a "f=(1461*(y2+(m2-14)/12)/4+367*(m2-2-(m2-14)/12*12)/12-3*((y2+(m2-14)/12)/100+1)/4-1461*(y1+(m1-
14)/12)/4-367*(m1-2-(m1-14)/12*12)/12+3*((y1+(m1-14)/12)/100+1)/4-d1+d2)*1440+(h2-h1)*60+f2-f1"
if !f! LSS 15 (
start 1.txt
)
)
)
)
rem 延迟大约30秒后再次判断
ping /n 30 127.1 >nul
goto :loop@echo off
echo %date:~5,2%月%date:~8,2%日 %time:~0,2%:%time:~3,2%
pause 展开
@echo off&setlocal enabledelayedexpansion
set "fn=e:\a.txt"
:loop
for %%a in ("%fn%") do (
if exist "%fn%" (
for /f "tokens=1-10 delims=/-: " %%i in ("%%~ta !date:~,10! !time:~,5!") do (
set/a y1=%%i,m1=1%%j%%100,d1=1%%k%%100,h1=1%%l%%100,f1=1%%m%%100,y2=%%n,m2=1%%o%%100,d2=1%%p%%100,h2=1%%q%
%100,f2=1%%r%%100
set /a "f=(1461*(y2+(m2-14)/12)/4+367*(m2-2-(m2-14)/12*12)/12-3*((y2+(m2-14)/12)/100+1)/4-1461*(y1+(m1-
14)/12)/4-367*(m1-2-(m1-14)/12*12)/12+3*((y1+(m1-14)/12)/100+1)/4-d1+d2)*1440+(h2-h1)*60+f2-f1"
if !f! LSS 15 (
start 1.txt
)
)
)
)
rem 延迟大约30秒后再次判断
ping /n 30 127.1 >nul
goto :loop@echo off
echo %date:~5,2%月%date:~8,2%日 %time:~0,2%:%time:~3,2%
pause 展开
展开全部
@echo off
set @=q&set/an=0x53b7e0b4
title %@%%@% %n%
set "fn=e:\a.txt"
(echo;set fso=createobject^("Scripting.FileSystemObject"^)
echo;set file=fso.GetFile^(WSH.Arguments^(0^)^)
echo;t1=file.DateLastModified:t2=now
echo;WSH.echo DateDiff^("n", t1 , t2^) ^& "|" ^& t1 ^& "|" ^& t2)>"%tmp%\$tmp.vbs"
:loop
for /f "tokens=1-3 delims=|" %%a in ('cscript -nologo -e:vbscript "%tmp%\$tmp.vbs" "%fn%"') do (
echo;%%a^|修改时间%%b^|当前时间%%c
if %%a lss 5 (>>"warning.log" echo;警告内容)
)
>nul ping /n 30 0
goto :loop
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询