I'm working on a script which have to check weather a file is younger than 2 hours. It should check in all folders and subfolders.
After finding a file younger than 2 hours, an email should be sent.
The script is working ok for the given folder, but I also need to check subfolders. And that's where I'm stuck.
I need some help in this one.
==================================
sPath = "c:\test"
'sPath = "c:\2"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
If oFiles.Count > 0 Then
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) < 120 Then
bolFileIsNewEnough = True
msgbox "Found file younger than 2 hours"
objShell.Run "C:\postie.exe -host:172.xx.xx.xx:26 -from:server@domain.com -to:me@domain.com -s:subject -msg:The_message "
Exit For
End If
End If
Next
On Error Goto 0
If Not bolFileIsNewEnough Then
MsgBox "All files are older than 2 hours."
End if
Else
MsgBox "Directory is empty"
End If
After finding a file younger than 2 hours, an email should be sent.
The script is working ok for the given folder, but I also need to check subfolders. And that's where I'm stuck.
I need some help in this one.
==================================
sPath = "c:\test"
'sPath = "c:\2"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
If oFiles.Count > 0 Then
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) < 120 Then
bolFileIsNewEnough = True
msgbox "Found file younger than 2 hours"
objShell.Run "C:\postie.exe -host:172.xx.xx.xx:26 -from:server@domain.com -to:me@domain.com -s:subject -msg:The_message "
Exit For
End If
End If
Next
On Error Goto 0
If Not bolFileIsNewEnough Then
MsgBox "All files are older than 2 hours."
End if
Else
MsgBox "Directory is empty"
End If