Skip to main content

Posts

Showing posts from September, 2010

How to watch for a file in a folder in VBS and handle locked files

The following Visual Basic Script allows you to  monitor a folder for new files. The script will try to process the file if the file is still locked by the application that created the file, an error will occur and the script will handle it by waiting a growing amount of time and then retrying to use the file. The script will also send an email alert about the error raised: strComputer = "." strPathToWatch = "C:\backups\" Sub SendMailMessage(to_address, subject, msg) dim sch, cdoConfig, cdoMessage sch = "http://schemas.microsoft.com/cdo/configuration/" Set cdoConfig = CreateObject("CDO.Configuration") With cdoConfig.Fields .Item(sch & "sendusing") = 2 ' cdoSendUsingPort .Item(sch & "smtpserver") = "yoursmtpserver" .update End With Set cdoMessage = CreateObject("CDO.Message") With cdoMessage Set .Configuration = cdoConfig ...