Solved

Copy one file into two locations

Posted on 2008-06-17
7
1,061 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
[X]
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
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
Independent Software Vendors: 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

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save and close already open Excel file using VBscript 9 97
Why use this lambda? 12 65
IDE for Python 5 73
MySQL programmer starter 25 29
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

726 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