Solved

Copy one file into two locations

Posted on 2008-06-17
7
1,057 Views
Last Modified: 2012-05-05
Hello,
I'm trying to write a simple VBScript to copy one file into two different folders.  The script works fine when broken into two separate scripts (one file one destination location) but throws an error message when combined (one file two destination locations).  The script I'm currently using is posted below.  
Thanks in advance.

Const OverwriteExisting = True
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "FileName", "C:\Destination1\", OverwriteExisting
objFSO.CopyFile "FileName","C:\Destination2\", OverwriteExisting

Open in new window

0
Comment
Question by:BalchBingham
  • 4
  • 3
7 Comments
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 250 total points
ID: 21804728
What is the error?  There shouldn't be anything wrong with that code as it stands, so long as you are not deleting the source file between copy statements (which you aren't in the above code).  CopyFile does exactly that.
0
 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 250 total points
ID: 21804782
In fact I've just tested your code snippet, and it works fine - if there is an error it is caused by another issue - does the target file exist in one of the locations, and is it open (i.e. locked) by an application?  This is an example of what would cause an error.
0
 

Author Comment

by:BalchBingham
ID: 21805074
The error given is a Runtime Error stating Permission Denied.  I am logged in as a Domain Admin so I should have adequate permission to run this.  I've also tried running it with the System Account; same error.  It runs without problem when it is only copying the file to one location, it's when it's copying to two locations that I'm having problems.
The target file does already exist in one location, but with the OverWrite command it shouldn't be an issue.  The file to be Over Written (a MS Word template file) is not in use.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 250 total points
ID: 21805219
If you are getting the permission denied error for the location in which the file does exist, then the file is not intrinsically writable.  This could be for a number of reasons:

- You don't have permission.  Just because you are logged in as an administrator doesn't mean you by default have permission to all files.  You need to actually check the permissions on the file.
- The file is on a share and is open by another user.
- The locked status of the file has been left by a hung application (e.g. Word crashes).  A system restart normally fixes this.
0
 

Author Comment

by:BalchBingham
ID: 21805379
I think you're on to something and I really appreciate your help.  I checked the security permission for not only the file but the folder itself and granted All Users Full Control.  I'm still getting the same error.  If I delete the file and then run the script it works great - once.  It will not OverWrite the file, gives me the same Permission Denied error.
I suppose I could have the script delete the pre-existing file and then copy in the new one, but in essence isn't that what Overwritting is doing?  And why would I have permission to delete the file but not copy over it?  
Being able to delete the file shows the file isn't in use (or hung).  The file is located in my local directory and is not being shared.  Good ideas though.
0
 

Author Comment

by:BalchBingham
ID: 21805491
Figured it out!  Was trying the script on test boxes that had freshly been imaged.  The file I was attempting (and failing) to copy down is a MS Word Template file.  Once Word was opened for the first time, the files copied as would be expected.  Not entirely sure why Word had to complete it's RunOnce sequence, but as long as it works now I'm happy.
Thanks for all of your help!
0
 

Author Closing Comment

by:BalchBingham
ID: 31468022
Thank you so much for taking the time to help me.  I had been banging my head against the wall, couldn't figure out why it wasn't working.  Turned out to be right in front of my face.  Thank you!!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question