Results 1 to 9 of 9

Thread: [RESOLVED] need help with filesys.copyfolder error handling

  1. #1
    Addicted Member
    Join Date
    Feb 12
    Location
    St. Louis, MO
    Posts
    166

    Resolved [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.

  2. #2
    Unmoderated abhijit's Avatar
    Join Date
    Jun 99
    Location
    Chit Chat Forum.
    Posts
    3,117

    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 File

  3. #3
    Addicted Member
    Join Date
    Feb 12
    Location
    St. Louis, MO
    Posts
    166

    Re: need help with filesys.copyfolder error handling

    Quote Originally Posted by abhijit View Post
    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

  4. #4
    PowerPoster
    Join Date
    Jun 01
    Location
    Trafalgar, IN
    Posts
    3,438

    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.

  5. #5
    Addicted Member
    Join Date
    Feb 12
    Location
    St. Louis, MO
    Posts
    166

    Re: need help with filesys.copyfolder error handling

    Quote Originally Posted by MarkT View Post
    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

  6. #6
    Addicted Member
    Join Date
    Feb 12
    Location
    St. Louis, MO
    Posts
    166

    Re: need help with filesys.copyfolder error handling

    Quote Originally Posted by MarkT View Post
    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

  7. #7
    Addicted Member
    Join Date
    Jul 09
    Posts
    208

    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.

  8. #8
    Addicted Member
    Join Date
    Feb 12
    Location
    St. Louis, MO
    Posts
    166

    Re: need help with filesys.copyfolder error handling

    Quote Originally Posted by His Nibbs View Post
    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

  9. #9
    Unmoderated abhijit's Avatar
    Join Date
    Jun 99
    Location
    Chit Chat Forum.
    Posts
    3,117

    Re: need help with filesys.copyfolder error handling

    The OPenTextFile method needs to be invoked with parameters. For example:

    vb Code:
    1. Set filesys = CreateObject("Scripting.FileSystemObject")
    2. 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 File

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •