Results 1 to 6 of 6

Thread: Missing Flash Drive Causes VBScript To Abort Copying

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Missing Flash Drive Causes VBScript To Abort Copying

    My OS: XP-PRO SP3

    I use the VBScript below to copy files and folders to different drives. This script allows my folders to retain their custom icons when copied. One of the destination folders "N:\APPS" is on a USB flash drive . I have discovered if my flash drive is not connected the script aborts the copying process when it can't find the drive. I would like to know if the script can be modified to ignore non existing destinations and continue
    to copy to the other valid destinations. I realize I could write the script so the copying to the flash drive would be the last operation but I am interested in finding out if this script could be modified as I explained above.



    Code:
                       On Error Resume Next
                 Const OverwriteExisting = True
                    set args = wscript.Arguments  
         set objShell = CreateObject("Shell.Application" )  
     
    Set objFolder = objShell.NameSpace("D:\Program Files" ) 
                         if not objFolder is nothing then  
                                 for each item in args   
                           objFolder.CopyHere item, 16  
                                               next  
    
    Set objFolder = objShell.NameSpace("N:\APPS" ) 
                         if not objFolder is nothing then  
                                 for each item in args   
                           objFolder.CopyHere item, 16  
                                               next 
    
    Set objFolder = objShell.NameSpace("W:\APPS" ) 
                         if not objFolder is nothing then  
                                 for each item in args   
                           objFolder.CopyHere item, 16  
                                               next 
    
    Set objFolder = objShell.NameSpace("X:\APPS" ) 
                         if not objFolder is nothing then  
                                 for each item in args   
                           objFolder.CopyHere item, 16  
                                               next 
    
                                               End If 
                                               End If 
                                               End If 
                                               End If
    Last edited by steve.marks59; Dec 8th, 2010 at 12:35 PM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Missing Flash Drive Causes VBScript To Abort Copying

    Thread moved from 'VB6 and Earlier' forum to 'ASP, VBScript' forum

    I can see the problem, but is rather hard to spot due to the lack of indenting of your code.

    For an explanation/example of how it should be, see the FAQ article What is indenting, and why should I do it?

    Once you have indented the code properly, the problem should be clear to you.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Re: Missing Flash Drive Causes VBScript To Abort Copying

    OK, I indented the script as you suggested and I see nothing in the code causing the script to abort other than the order of the drives. Please explain to what you are referring to by your statement "Once you have indented the code properly, the problem should be clear to you". Thank you for taking the time to help me.

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Missing Flash Drive Causes VBScript To Abort Copying

    Every if statement should have an accompanying end if. What you have done is nested them all. Once one of the objects = nothing then you will exit.

    The proper indentation is below. Does that make it easier to see the problem.
    Code:
        On Error Resume Next
        Const OverwriteExisting = True
        Set args = wscript.Arguments
        Set objShell = CreateObject("Shell.Application")
        
        Set objFolder = objShell.NameSpace("D:\Program Files")
        If Not objFolder Is Nothing Then
            For Each Item In args
                objFolder.CopyHere Item, 16
            Next
            
            Set objFolder = objShell.NameSpace("N:\APPS")
            If Not objFolder Is Nothing Then
                For Each Item In args
                    objFolder.CopyHere Item, 16
                Next
                
                Set objFolder = objShell.NameSpace("W:\APPS")
                If Not objFolder Is Nothing Then
                    For Each Item In args
                        objFolder.CopyHere Item, 16
                    Next
                    
                    Set objFolder = objShell.NameSpace("X:\APPS")
                    If Not objFolder Is Nothing Then
                        For Each Item In args
                            objFolder.CopyHere Item, 16
                        Next
                    End If
                End If
            End If
        End If
    Last edited by MarkT; Dec 8th, 2010 at 01:18 PM. Reason: added the code properly indented

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Re: Missing Flash Drive Causes VBScript To Abort Copying

    My Problem was solved on another forum.
    Here is the link:

    http://www.tek-tips.com/viewthread.c...1630508&page=1

    This script given to me there works perfectly.


    Code:
    set args = wscript.Arguments  
    set objShell = CreateObject("Shell.Application" )  
    
    Set objFolder = objShell.NameSpace("D:\Program Files" )
    if not objFolder is nothing then  
     for each item in args   
      objFolder.CopyHere item, 16  
     next  
    End If
    Set objFolder = Nothing
    '
    Set objFolder = objShell.NameSpace("N:\APPS" )
    if not objFolder is nothing then  
     for each item in args   
      objFolder.CopyHere item, 16  
     next  
    End If
    Set objFolder = Nothing
    '
    Set objFolder = objShell.NameSpace("W:\APPS" )
    if not objFolder is nothing then  
     for each item in args   
      objFolder.CopyHere item, 16  
     next  
    End If
    Set objFolder = Nothing
    '
    Set objFolder = objShell.NameSpace("X:\APPS" )
    if not objFolder is nothing then  
     for each item in args   
      objFolder.CopyHere item, 16  
     next  
    End If
    Set objFolder = Nothing

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    18

    Re: Missing Flash Drive Causes VBScript To Abort Copying

    When one of the destination folders is the same as the source I get the following prompt:


    "Error Copying File or Folder
    Cannot copy******* .The source and Destination are the same
    OK "

    I click the "OK" button and the script continues.

    Is it possible to eliminate the prompt?

    I would like the script to automatically answer "OK".

Posting Permissions

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



Click Here to Expand Forum to Full Width