Check for any file older than X minutes in a directory

Below script could e.g. be used to monitor a directory where a fax is converted into a email.
If the directory is not empty within the "age_threshold" it should result in an alarm.

In custom.conf:

[Check for old files in C:\Path]
type=boolean
command=cscript /nologo C:\oldestfile.vbs C:\Path\

In oldestfile.vbs:


' This script processes the list of files in the directory passed as argument
' and returns 1 if any file is older than "age_threshold" minutes

' File age threshold in minutes
Dim age_threshold
age_threshold = 5000

Dim folder_path
folder_path = WScript.Arguments(0)

Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.getFolder(folder_path)
Dim old_file_not_found
old_file_found = 0
For Each file in f.Files
  Dim age
  age = DateDiff("n", file.DateLastModified, Now)
  If age > age_threshold Then
    old_file_found = 1
    Exit For
  End If
Next
WScript.Quit(old_file_found)