|
-
Jun 18th, 2012, 05:42 PM
#1
Thread Starter
Addicted Member
[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
Last edited by sheetzdw; Jun 18th, 2012 at 06:12 PM.
-
Jun 19th, 2012, 09:56 AM
#2
Re: need help with filesys.copyfolder error handling
Create a collection to store all error messages. Then output the collection to the log file.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Jun 19th, 2012, 01:51 PM
#3
Thread Starter
Addicted Member
Re: need help with filesys.copyfolder error handling
 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
-
Jun 19th, 2012, 05:52 PM
#4
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.
-
Jun 19th, 2012, 06:53 PM
#5
Thread Starter
Addicted Member
Re: need help with filesys.copyfolder error handling
 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
-
Jun 20th, 2012, 01:41 PM
#6
Thread Starter
Addicted Member
Re: need help with filesys.copyfolder error handling
 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
-
Jun 20th, 2012, 03:16 PM
#7
Addicted Member
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.
-
Jun 20th, 2012, 04:12 PM
#8
Thread Starter
Addicted Member
Re: need help with filesys.copyfolder error handling
 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
-
Jun 22nd, 2012, 07:33 AM
#9
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.
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|