/build/static/layout/Breadcrumb_cap_w.png

Search for files modified within the last five minutes

I'm completely new to programming and scripting. I need a script that searches a folder for a file named *_single.xml and a file named *_full.xml. It must find at least one of each that has been modified within the last five minutes. If either one of these files does not exist with a last modified date of within five minutes, the script will fire a windows event. The script I have right now checks a specific file to see if it has been checked within five minutes, but now I need the script to search the folder for those two files and check the date modified on all results. Here's my current script. Thanks in advance for any help!
----------------------------------------------------------------------------------------------------------
Option Explicit

'* DEFINE CONSTANTS
Const EVENT_ERROR = 1
Const EVENT_INFORMATIONAL = 4

'* DECLARE VARIABLES

Dim objShell, objExecObject, strText
Dim FSO,File
Dim Date1,Date2,Hour1,Hour2

'* Set environment and open output file

Set objShell = WScript.CreateObject("WScript.Shell")
set FSO=CreateObject("Scripting.FileSystemObject")
Set File=FSO.GetFile("c:\test\test.txt")

Date1=Now()
Date2=File.DateLastModified
'wscript.echo DateDiff("s",Date2,Date1),"Seconds"

If DateDiff("s",Date2,Date1) > 300 then
objShell.LogEvent EVENT_ERROR, "file has not been written to within the last 5 minutes"
End if
[font="times new roman"]

0 Comments   [ + ] Show comments

Answers (1)

Posted by: anonymous_9363 15 years ago
Red Belt
0
Not a bad start! :)

There must be a quadzillion sample files on the web for searching a folder for files which could easily be adapted. Try http://www.computerperformance.co.uk as a kick-off.

Remember 1) that indentation makes your code easier to read and 2) to use the CODE tag for code (and other lengthy text):If DateDiff("s",Date2,Date1) > 300 then
objShell.LogEvent EVENT_ERROR, "file has not been written to within the last 5 minutes"
End If
You access the tag by clicking the button marked '<%' in the 'Message' window or, much quicker, by typing a left square bracket, the word 'code', then a right square bracket. Close the tag by prefixing the word 'code' with a forward slash, '/'.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ