[RESOLVED] need help with filesys.copyfolder error handling
Ihave a script that copies folders ok, but if any folder or file fails to copy it stops my script.
How can I add error handling to write a log if it cant write a file and give the reason then continue to the next file?
some thing like what I found below but I guess I need to break it down somehow because I want each file error to be written and only skip 1 file not a whole folder
Code:
On Error Resume Next
DoStep1
If Err.Number <> 0 Then
WScript.Echo "Error in DoStep1: " & Err.Description
Err.Clear
End If
DoStep2
If Err.Number <> 0 Then
WScript.Echo "Error in DoStop2:" & Err.Description
Err.Clear
End If
Re: need help with filesys.copyfolder error handling
Create a collection to store all error messages. Then output the collection to the log file.
Re: need help with filesys.copyfolder error handling
Quote:
Originally Posted by
abhijit
Create a collection to store all error messages. Then output the collection to the log file.
SOunds good not sure how to do that in vb script
Re: need help with filesys.copyfolder error handling
Showing the script and where you are having errors would be the best way to get this answered.
Re: need help with filesys.copyfolder error handling
Quote:
Originally Posted by
MarkT
Showing the script and where you are having errors would be the best way to get this answered.
Thanks will post soon as I figure out the logic and write it all down, I get a lot of interuptions but will post my code tomorrow
Re: need help with filesys.copyfolder error handling
Quote:
Originally Posted by
MarkT
Showing the script and where you are having errors would be the best way to get this answered.
here is what I have so far (not even using a collection yet)
I get error on the second line at character 50 "Syntax Error"
Code:
On Error Resume Next
WSHShell.Run("c:\windows\system32\robocopy.exe" \\10.150.221.110\C$\Documents and Settings\cacharu\My Documents, C:\Users\cacharu /E /R:10 /W:10 /Z /Log+:C:\mydocs.log")
If Err.Number <> 0 Then
objTextFile.WriteLine "Error Copying My Documents Folder: "& Err.Description
Err.Clear
Re: need help with filesys.copyfolder error handling
Without me seeing the Robocopy help, try deleting the second quote. Arguments containing spaces might need to be surrounded by quotes - use Chr(34) for this - again check the help.
Re: need help with filesys.copyfolder error handling
Quote:
Originally Posted by
His Nibbs
Without me seeing the Robocopy help, try deleting the second quote. Arguments containing spaces might need to be surrounded by quotes - use Chr(34) for this - again check the help.
here is my working line
WSHShell.Run("""c:\windows\system32\robocopy.exe"" ""\\10.150.221.110\C$\Documents and Settings\cacharu\Desktop"" ""C:\Users\cacharu"" /E /R:10 /W:10 /Z /Log+:C:\MyDesk.log""")
but now I get error ( Object doesn't support this property ) on a previous line
Set objFSO = CreateObject("Scripting.FileSystemObject")
objTextFile = objFSO.OpenTextFile
Re: need help with filesys.copyfolder error handling
The OPenTextFile method needs to be invoked with parameters. For example:
vb Code:
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("c:\temp\somefile.txt", 2, True)
The 2 indicates for writing.