Looking for a little help with working on error handling in VBscript.
What I am trying to do is tell the script that if an error occurs during one of the commands that it should re run the script. Basically I am just zipping some files and copying them over to a shared drive, then deleting the original copies once the copy is complete. Now if an error occurs in the zip or copy process I don't want the rest of the script running and having it delete the files. So I just need the script to start over.
At the moment all I have it doing is printing out an echo that says "An error has occurred re-run script" but this is going to be done as a scheduled task so I really need it to be automated. I am just not sure how the syntax would work for this or if it is even possible.
I have seen "On Error Resume Next" but not sure how that plays into how I should be writing this. I don't think I Should be using it because I do not want the script to continue if an error occurs I just want it to start from the beginning again.
This is what it looks like at the moment:
Command2 = "Robocopy.exe " & sLocalDestinationPath & " " & sFinalDestinationPath
RetVal = Shell.Run(Command2,0,true)
If err.Number <> 0 Then
'WScript.Echo "An error has occured copying the files, re-run Script."
End If
If I am going at this problem the wrong way and there is something more efficient I should be doing I would appreciate the help greatly. I am new to VBscript and I am still getting used to it.
if an error occurs during one of the commands that it should re run the script
wouldn't that cause an endless loop? Nothing has changed, so the error would occur again, which would cause the script to start again, which would cause the error again, which would cause the script to start again, and on and on and on ... – JimmyPenaCommand2 = "Robocopy.exe """ & sLocalDestinationPath & """ """ & sFinalDestinationPath & """"
. A call likeRobocopy.exe c:\my tests\test 1 c:\my results\result 1
will now becomeRobocopy.exe "c:\my tests\test 1" "c:\my results\result 1"
– AutomatedChaos