Link to home
Start Free TrialLog in
Avatar of spen_lang
spen_lang

asked on

Loop within a loop

I have the following script that checks a folder every 10 minutes and then emails us if the folder has more than 500 files.

What I want to do is embed another loop that checks again to see if there are less that 200 files.

The idea being, it sends us an email if there are more than 500 files, but then won't send us any more emails until the file count has dropped below 200 and then raised back above 500 again.

Can anyone help me?


Andrew
strComputer = "lang-apps"
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Do While True
    Set colFileList = objWMIService.ExecQuery _
        ("ASSOCIATORS OF {Win32_Directory.Name='D:\Mandata\WebInterface\Exports'} Where " _
            & "ResultClass = CIM_DataFile")
 
    		If colFileList.Count >= 500 Then
 
			Set objEmail = CreateObject("CDO.Message")
			objEmail.From = "WEB_INTERFACE"
			objEmail.To = "it@xxxx.co.uk"
			objEmail.Subject = "WEB INTERFACE"
			objEmail.Textbody = "There are " & colFileList.Count & " items in the Exports folder on Lang-Apps!       \\lang-apps\Mandata\WebInterface\Exports"
			objEmail.Configuration.Fields.Item _
			 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
			objEmail.Configuration.Fields.Item _
			 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
			"192.168.73.112"
			objEmail.Configuration.Fields.Item _
			 ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
			objEmail.Configuration.Fields.Update
			objEmail.Send
 
    		End If
 
    Wscript.Sleep 600000
 
Loop

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial