×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Missing Flash Drive Aborts VBScript Copying

Missing Flash Drive Aborts VBScript Copying

Missing Flash Drive Aborts VBScript Copying

(OP)
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.


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












 

RE: Missing Flash Drive Aborts VBScript Copying

youve got your 'end if's in the wrong place. if you indented you code you would find this easier to spot. in addition, your script has no comments, no echo's to the screen, if it did it would have shown you what was going wrong

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
 

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald

RE: Missing Flash Drive Aborts VBScript Copying

(OP)
Thank you very much mrmovie. Your modification made the script do exactly what I wanted. I only had to include the third and fourth lines from the original script. The script I will use now is:

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


 

RE: Missing Flash Drive Aborts VBScript Copying

(OP)
I am really amazed and appreciate the code you gave me. While using it today I discovered it also did something I really wanted the script to do but was told on several forums it was not possible. Here is what I asked:

Do you know how this script could be modified so it would ignore the error if the source and destination were the same. This would allow me to have the same script in my folders on various drives. The original copy script you gave me a while back would ignore the error and continue. I tried inserting these two lines from the original script

------------------------------------
On Error Resume Next
Const OverwriteExisting = True
-------------------------------

to the to the top of the new script but it did not make a difference. I realize it may not be possible with this code but I figured if anyone would know how chances are it would be you. Regardless, I am very happy with this script and this is only a very minor detail I would like to change. Thanks.



The reply I was given:

 Posted 25 October 2010 - 06:30 AM
The error you get is an Explorer error and not a script error. This because the method uses the explorer shell to copy the items.
So using the On Error Resume Next wont help in this one.. The only work around would be (If exists) to search for an other VB method which also copies the attributes. :)




 

RE: Missing Flash Drive Aborts VBScript Copying

(OP)
Is it possible to eliminate the prompt?

"Error Copying File or Folder
Cannot copy******* .The source and Destination are the same
       OK                  "
I would like the script to automatically answer "OK".

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close