Checking for new files within a time period

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
alanimal
Junior Coder
Posts: 40
Joined: Thu Jun 09, 2005 11:57 pm

Checking for new files within a time period

Post by alanimal » Wed Jun 07, 2006 1:00 am

Hi there,

I am trying to create a script that will notify me if a file has not been received within a certain time period. I would probably schedule this script to run several times during the day

We have a system where email files get processed and then copied to a folder on our server. These *.eml files come from different countries and are sorted into several folders.

What I would like to accomplish is to scan each folder, and if a *.eml file has not been received within a time period of 1 hour, an email will be sent to myself to say "OI no email messages are coming in from Australia" or something, and a message to display on screen the date and time of the last modified file.

the folders are in C:\Inetpub\mailroot\Mailbox\\\\\, and each folder contains a few hundred thousand eml files.

Any help on this would be appreciated.
Cheers

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jun 07, 2006 3:47 am

It would be helpful if you could show us what you have so far. I know how I might do this but I have inside info about my network. I don't know much about yours.

The situation of dealing with hundreds of thousands of files could be relieved if you can turn off the archive bit on all existing files. DOS dir /AA can then give you a list of newly created files. (A much smaller list to sort through.) As you work through the new files the archive bit can be turned off on the files as they are processed by using attrib -A [filename], keeping the list short.

As for acquiring file date and time, this thread can help you get started

Hope this helps,
Dick

alanimal
Junior Coder
Posts: 40
Joined: Thu Jun 09, 2005 11:57 pm

Post by alanimal » Wed Jun 07, 2006 4:15 am

Hi Dick,

I have this so far but it only displays the last filename - all i need now is to check if the lastfilename modifytime is less or greater than a specified period of say 90minutes - and if greater send an email using the smtp command. Almost there!

Code: Select all

Let> dir =(C:\Inetpub\mailroot\drop\)

VBSTART

Function LastModified(folderspec)
   Dim fso, f, f1, fc, s, lastfiledate, latestfile
   lastfiledate = 0
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder("C:\Inetpub\mailroot\drop\") 
   Set fc = f.Files
   For Each f1 in fc
      If f1.DateLastModified > lastfiledate then
      lastfiledate = f1.DateLastModified
  latestfile = f1.Name
  end if
   Next
   LastModified = latestfile 
End Function

VBEND

VBEval>LastModified("%dir%"),file
MessageModal>Last Modified File in %dir% is %file%  %lastfiledate%


User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jun 07, 2006 4:57 am

I ran this script substituting a directory on my C: drive. all I get is the filename of the newest file in the directory, I don't get anything for a file date or time.

I know nothing about VBscript and have no idea how you should proceed from here.

As I alluded earlier, I'd use a DOS solution.

There are a number of VB experts on this forum, perhaps one of them can help?

Later,
Dick

alanimal
Junior Coder
Posts: 40
Joined: Thu Jun 09, 2005 11:57 pm

Post by alanimal » Wed Jun 07, 2006 11:43 pm

Thanks Dick,

This is what I am trying to get to:

Basically i have a set of folders which contain files that have been processed by an agent writing data to an sql db. These files are *.eml files and these folders are updated with new files at a rate of approximately 10 per second.

What i would like to do, is scan the folders and if each folder has a file that has been modified within the last 90 minutes, then just to display to screen something like this:

_________________________________________
Current Time: 08 June 2006 11:26AM
Folder: Mod Date:

CHS 08 June 2006 11:20AM
DAR 08 June 2006 11:21AM
COB 08 June 2006 11:26AM
DIA 08 June 2006 11:25AM
__________________________________________

As you can see it displays the date and time, the folder scanned and the timestamp for the last message received.

The above shows that messages have been coming through without any problems. And below is what I would like to display if there is a problem:
_________________________________________
Current Time: 08 June 2006 11:26AM
Folder: Mod Date:

CHS 08 June 2006 11:20AM
DAR 08 June 2006 11:21AM
COB 08 June 2006 08:26AM ERROR! NO MESSAGES FOR 180 minutes.
DIA 08 June 2006 11:25AM
__________________________________________

As you can see it has picked up that no messages have come through to the \\COB\ folder for 3 hours, so we display the alert to screen and using an SMTP command an email is sent to let the appropriate people know that no data is coming in from the COB system.

All the folders containing these files are in the same directory.

If anyone could shed any light on a script that would be capable of doing this it would be so appreciated!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts