Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email when files exist in multiple folders over 15min

Status
Not open for further replies.

billiehawkins

Technical User
Nov 17, 2011
2
US
I have a list of directories that get files added to by other users on my network.

I would like a script (triggered by scheduled task) that would detect if there are files in these folders older than 15 minutes, and send me an email.

I am able to run Batch/DOS, Python, Perl, or VBS - I have them all installed on the server. As long as they can be triggered from Scheduled task.

Example:
C:\UsersFTP\JoeS\FromCustomer\ <files dropped here>
C:\UsersFTP\Mark\FromCustomer\ <files dropped here>
C:\UsersFTP\Robbie\FromCustomer\ <files dropped here>
C:\UsersFTP\Tammy\FromCustomer\ <files dropped here>

- Check every 15 minutes if any FILES exist in these directories (along with 50 more).
- It should ignore folders.
- If No, quit.
- If yes, email user@emailaddress.com and notify that files are waiting to be reviewed.
- The scheduled task can run it every 15 minutes.
- I would like it to only send ONE email, no matter how many files are waiting.

Example notification: (the XX are variables)

= = = = =
From: Notifer@youremail.com
To: user@emailaddress.com
Subject: Files in FromCustomer are waiting


You Have files that are waiting since xx:xx:xx PM (over XX minutes).

The files are located in:

C:\UsersFTP\Tammy\FromCustomerC:\UsersFTP\Robbie\FromCustomer
Please process or remove them. Thank you.

= = = = =

I have been looking at doing this in Batch, but I just don't think it is capable... I can read and understand VB, but I am not great at writing it... Thoughts, help?
 
Hi ! Try to do like this based on DateDiff Function
Code:
Set fso = CreateObject("Scripting.FileSystemObject")
userlist = Array("JoeS", "Mark", "Robbie", "Tammy")
OldFile = False

For Each user In userlist
 For Each f In fso.GetFolder("C:\UsersFTP\" & user & "\FromCustomer").Files
 If DateDiff("n", f.DateLastModified, Now) > 15 Then OldFile = True
 Next
Next

If OldFile Then 
'send mail ....
........
 
for sending email...

Code:
function email (strTo, strFrom, strSubject, strBody)
	on error resume next
	
	set objEmail = CreateObject("CDO.Message")
	objEmail.From = strFrom
	objEmail.To = strTo
	objEmail.Subject = strSubject
	objEmail.Textbody = strBody
	objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
	objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = [red]"my.Exchange.Server[/red]"
	objEmail.Configuration.Fields.Item ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
	objEmail.Configuration.Fields.Update
	objEmail.Send
	
end function

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thank you for the tips... I was able to create a solution:



'------------------- Billie Hawkins ---------------------
'------------------- Check Files VBS ---------------------



'Dim ShowFolderList(folderspec)
Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim folderspec
Dim fs, f, f1, fc, s
folderspec = "C:\Users\"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 in fc
s = s & f1.name
's = s & vbCrLf




sPath = "C:\Users\" & f1.name & "\FromCustomer"
'wscript.echo sPath

Set oFolder = oFSO.GetFolder(sPath)
On Error Resume Next
Set oFiles = oFolder.Files

If oFiles.Count > 0 Then

' Enumerate the files in the folder looking for files updated
' within the last xx minutes. If such a file is found, exit the loop.

bolFileIsNewEnough = False ' init value
For Each oFile In oFiles
On Error Resume Next
dFileModDate = oFile.DateLastModified
If Err.Number = 0 Then
If DateDiff("n", dFileModDate, Now) < 15 Then
bolFileIsNewEnough = True
Exit For
End If
End If
Next
On Error Goto 0

If Not bolFileIsNewEnough Then
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "File-Alert@msbinfo.com"
objEmail.To = "billie.hawkins@email.com"
objEmail.Subject = "Error: Files sitting over 15 minutes. "
objEmail.Textbody = sPath & " has files older than 15 Min." & VBCRLF & " Please check."


objEmail.Configuration.Fields.Item _
(" = 2
objEmail.Configuration.Fields.Item _
(" = "my.smtp.com"
objEmail.Configuration.Fields.Item _
(" = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End if

Else
'WScript.Echo "Directory is empty"
End If
Next

'--------------------Billie Check Files VBS----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top