|
Answer» I need a DOS Script that will look at a directory for the latest file with extension XXX. It will determine how many hours old the file is. And then I will echo back a response if the the file is XX hours old. Thanks in advance. JoshWhat have you done so far? I'm very new to scripting and other than researching a possible solution online, I have nothing. I know how to grab the most recent XXX file in the FOLDER but need to know how to evaluation the timestamp and figure an HOUR age based on current time. In what I'm seeing online it seems like DATE determination in DOS scripts is not an easy thing to do. Thanks for any information you can give me.Code: [Select]@echo off
REM Create VBScript REM Get difference between file date and now in minutes echo filename=wscript.arguments(0)>fileage.vbs echo Set filesys = CreateObject("Scripting.FileSystemObject")>>fileage.vbs echo Set Myfile = filesys.GetFile(filename)>>fileage.vbs echo wscript.echo DateDiff("n", Myfile.DateCreated, Now())>>fileage.vbs
REM set file extension set fileExt=.txt
REM set age limit set agelimit=60
REM get file creation date of OLDEST file of DESIRED extension for /f "delims=" %%A in ('dir /b /tc /o-d *%fileExt%') do set file=%%~nxA
REM Pass file name to VBScript and capture the output For /f "delims=" %%A in ( ' cscript //nologo fileage.vbs "%file%" ' ) do set AgeInMinutes=%%A
REM Get file creation date For /f "delims=" %%A in ( 'dir /b /tc "%file%" ' ) do set FileDate=%%~tA
echo file name %file% echo file created %FileDate% echo file age (min) %AgeInMinutes%
if %AgeInMinutes% LEQ %agelimit% goto UnderOrEqual if %AgeInMinutes% GTR %agelimit% goto Over
:UnderOrEqual
REM Code here to be run if file age is less than or equal to limit echo file is not older than %agelimit% minutes goto end
:Over
REM Code here to be run if file age is greater than limit echo file is older than %agelimit% minutes
:end
|