SoFunction
Updated on 2025-03-10

Batch bat determines whether a file has been updated in the last 5 minutes


@echo off
set SrcFile=D:/
for /f "skip=5 tokens=1-2 delims= " %%a in ('dir /tw "%SrcFile%"') do (
    set "FileDay=%%a %%b"
    goto :compare
)
:compare
call :DateToMins %FileDay:~0,4% %FileDay:~5,2% %FileDay:~8,2% %FileDay:~11,2% %FileDay:~14,3% mFileDay
call :DateToMins %date:~4,4% %date:~9,2% %date:~12,2% %time:~0,2% %time:~3,2% mToday
set /a mMinus=mToday-mFileDay
if %mMinus% gtr 5 (
    echo "The system is down"
) else (
    echo "The system is running"
)
pause
goto :eof

:DateToMins %yy% %mm% %dd% %hh% %mm% result
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
if 1%hh% LSS 20 set hh=0%hh%
if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
endlocal&set %6=%j%&goto :EOF