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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check all files using For each but trigger action only once

Status
Not open for further replies.

BigC72

MIS
Oct 15, 2004
69
US
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.

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
 
...
shell.run "C:\stopBWS.bat"
[!]Exit For[/!]
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks...didn't realize that the For could be exited in such a fashion...

Appreciate you posting.

BC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top