I have a script that is looking at a directory and if files are present it's looking at the file extension and then age (in minutes) of the file(s) and if the file or files are beyond that age it triggers another set of actions...
What I'm not certain of is how to get the script to trigger the subsequent actions only once versus once for each file that fits the above criteria? I've messed around trying to include a Do loop but either am not utilizing it correctly or it won't work in this situation as the actions "fire" for each file in the directory that fits the LastDateModified criteria.
Here is what I have to this point and it works fine with the one noted exception.
What I'm not certain of is how to get the script to trigger the subsequent actions only once versus once for each file that fits the above criteria? I've messed around trying to include a Do loop but either am not utilizing it correctly or it won't work in this situation as the actions "fire" for each file in the directory that fits the LastDateModified criteria.
Here is what I have to this point and it works fine with the one noted exception.
Code:
Option Explicit
CONST ForWriting = 2
dim strPathimp12
dim restart12
dim shell, fso, objLogFile, objFolder, colFiles, objFile, strFile, tday
Set shell = createobject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
set objLogFile = fso.CreateTextFile("E:\inserver6\log\AgentMonitor.txt", ForWriting, True)
tday = Now()
strPathimp12 = "\\anh-efr\IN_Output"
'===========This segment looks at the ImportAgent12 service which handles the ImagePortal documents from Access eForms
If fso.FolderExists(strPathimp12) Then
Set objFolder = fso.GetFolder(strPathimp12)
Set colFiles = objFolder.Files
Else objLogFile.Write "ImagePortal source directory could not be located on: " & Now & "."
objLogFile.WriteLine
End if
If objFolder.Files.Count > 1 Then
For each strFile in colFiles
Set objFile = fso.GetFile(strFile)
If fso.GetExtensionName(strFile) = "tif" Then
If DateDiff("n",objFile.DateLastModified, tday) > 5 then
shell.run "C:\impMon\restartImp12.bat"
shell.run "C:\impMon\BWSrestartemail.bat"
objLogFile.Write "ImagePortal import agent service (inserverImp12) was restarted on : " & Now & "."
objLogFile.WriteLine
Wscript.Sleep(15000)
shell.run "C:\stopBWS.bat"
End if
End if
set objFolder = nothing
set colFiles = nothing
set objFile = nothing
Next
End if