Copy one file into two locations

Posted on 2008-06-17
Medium Priority
Last Modified: 2012-05-05
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

Question by:BalchBingham
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 24

Accepted Solution

purplepomegranite earned 1000 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.
LVL 24

Assisted Solution

purplepomegranite earned 1000 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.

Author Comment

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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 24

Assisted Solution

purplepomegranite earned 1000 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.

Author Comment

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.

Author Comment

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!

Author Closing Comment

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!!

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

800 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