Okay, I think I'm on to somthing but cannot seem to make it work.
As found on this site:
http://www.winfrastructure.net/article.aspx?BlogEntry=VBScript-to-check-if-folder-is-empty What I'm trying to do is see if either oFolder is empty then set it to another folder with a generic image placed in it, using something like so:
If oFolder.Files.Count = 0 Then
Set oFolder = aqFileSystem.GetFolderInfo("F:\temp2")
End IfBut I keep getting an error. If anyone has any suggestions, I'm all ears...
UPDATE:
I've managed to get it working. Basically, I am now using the following two scripts:
For taking screenshots:
Sub Main
If aqFileSystem.Exists("F:\temp") Then
Sys.Desktop.ActiveWindow().Picture.SaveToFile "F:\temp\" + VarToStr(Project.Variables.Screenshot_Filename)
Else
aqFileSystem.CreateFolder("F:\temp")
Sys.Desktop.ActiveWindow().Picture.SaveToFile "F:\temp\" + VarToStr(Project.Variables.Screenshot_Filename)
End If
End Sub And emailing logs/screenshots:
Function SendEmail(mFrom, mTo, mSubject, mBody, mAttachment)
Err.Clear
On Error Resume Next
schema = "http://schemas.microsoft.com/cdo/configuration/"
Set mConfig = Sys.OleObject("CDO.Configuration")
mConfig.Fields.Item(schema + "sendusing") = 2 ' cdoSendUsingPort
mConfig.Fields.Item(schema + "smtpserver") = "smtp.mailserver.address" ' SMTP server
mConfig.Fields.Item(schema + "smtpserverport") = 25 ' Port number
' mConfig.Fields.Item(schema + "sendusername") = "" ' User name (if needed)
' mConfig.Fields.Item(schema + "sendpassword") = "" ' User password (if needed)
mConfig.Fields.Update()
Set mMessage = Sys.OleObject("CDO.Message")
mMessage.Configuration = mConfig
mMessage.From = mFrom
mMessage.To = mTo
mMessage.Subject = mSubject
mMessage.HTMLBody = mBody
aqString.ListSeparator = ","
For i = 0 To aqString.GetListLength(mAttachment) - 1
mMessage.AddAttachment aqString.GetListItem(mAttachment, i)
Next
mMessage.Send
If Err.Number > 0 Then
Log.Error "E-mail cannot be sent", Err.Description
SendEMail = False
Else
Log.Message "Message to <" + mTo + "> was successfully sent"
SendEMail = True
End If
End Function
Sub MainTest
' checks to see if there are any existing screenshots
If aqFileSystem.Exists("F:\temp") Then
Set oFolder = aqFileSystem.GetFolderInfo("F:\temp")
Else
Set oFolder = aqFileSystem.GetFolderInfo("F:\temp2")
End If
Set colFiles = oFolder.Files
strFileList = ""
aqString.ListSeparator = ","
While colFiles.HasNext
Set f = colFiles.Next
strFileList = aqString.AddListItem(oFolder.Path + "\" + f.Name, strFileList)
Wend
ListFiles = strFileList
' this executes the email function
If SendEmail("from@email.com", "to@email.com", "Subject", _
"Message Body", "" + ListFiles + "") Then
' Message was sent
Else
' Message was not sent
End If
' deletes the screenshot folder
If aqFileSystem.Exists("F:\temp") Then
For Each aFile In oFolder.Files
aFile.Delete
Next
aqFileSystem.DeleteFolder("F:\temp")
End If
End SubAnd as long as I set my variable for the screenshot filename (along with some other stuff that I removed from the example above) it works beautifully! (and I didn't erase my entire C: drive in the process!)
So thanks for letting me chat to myself on here today :) Regardless, I have it working the way I like and I couldn't have gotten to this point without all of your help.
Thanks again!