|
MRIS -> RE: SOLUTION: Monitor Function to Check for old Files (8.Jul.2008 4:24:36 AM)
|
trwagner1's solution to this is excellent. However I had already solved a problem similar to this with the following script. I'm not saying this script is better, it's just another way. This script is different in two ways. The first difference is that it checks an actual specific file, rather than a folder. The second difference is that it accepts the number of hours as one of the script arguments, allowing the same script to be re-used in multiple checks. For example one check may test if a file is older than, say 1 hour, and another check may check if another file is say, 24 hours old.
' /////////////////////////////////////////////////////////////////////////////
' Accepts 2 parameters
' First parameter is the UNC path of the file, eg "\\server\path\file.txt"
' Second parameter is the age in hours
' the check reports success if the age in hours of the file is newer than this number.
' /////////////////////////////////////////////////////////////////////////////
Option Explicit
Const retvalUnknown = 1
Function IsFileNewerThanHours(TheFile,Hours)
' This file designed, created, tested and deployed by MRIS
On Error Resume Next
Dim fso, f, FileDateCreated, AgeInHours
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(TheFile)
FileDateCreated = f.DateLastModified
AgeInHours = DateDiff("h",FileDateCreated,Now)
If AgeInHours > Hours then
EXPLANATION = TheFile & " is " & AgeInHours & " hours old, which is more than " & Hours & " hours."
IsFileNewerThanHours = False
End If
If AgeInHours <= Hours then
EXPLANATION = TheFile & " is " & AgeInHours & " hours old, which is less than " & Hours & " hours."
IsFileNewerThanHours = True
End If
End Function
|
|
|
|