I have never used error handling before and wonder where to put the 'error monitoring'. Here is a script that I use:
'VB Script - Archive Outbound FTP Files (pgp format)
Dim filesys, file, folderName, objFile, folderObj, fileColl, objRegExp, newFile
Set filesys = CreateObject("Scripting.FileSystemObject")
folderName = "e:\ftpdata\toreliance\"
Set folderObj = filesys.GetFolder(folderName)
Set fileColl = folderObj.Files
Set objRegExp = New RegExp
objRegExp.Pattern = ".asc" 'looking for files with = ".asc" extension
objRegExp.IgnoreCase = True
'archive files
For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then
filesys.MoveFile objFile, folderName & "archive\" & newFile
End If
Next
I assume that an error could occur in the 'For Each' loop. There could be a case that there are no files to archive and that is OK and should not generate an error. An error could be that the 'archive' folder has been deleted or changed as an example. So where should I put the error monitoring? Within the 'For Each' or right after?
This is what I had in mind:
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
'here I plan to write to a log file
Wscript.Quit
End If
Thank you.
'VB Script - Archive Outbound FTP Files (pgp format)
Dim filesys, file, folderName, objFile, folderObj, fileColl, objRegExp, newFile
Set filesys = CreateObject("Scripting.FileSystemObject")
folderName = "e:\ftpdata\toreliance\"
Set folderObj = filesys.GetFolder(folderName)
Set fileColl = folderObj.Files
Set objRegExp = New RegExp
objRegExp.Pattern = ".asc" 'looking for files with = ".asc" extension
objRegExp.IgnoreCase = True
'archive files
For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then
filesys.MoveFile objFile, folderName & "archive\" & newFile
End If
Next
I assume that an error could occur in the 'For Each' loop. There could be a case that there are no files to archive and that is OK and should not generate an error. An error could be that the 'archive' folder has been deleted or changed as an example. So where should I put the error monitoring? Within the 'For Each' or right after?
This is what I had in mind:
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
'here I plan to write to a log file
Wscript.Quit
End If
Thank you.