[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1078
  • Last Modified:

Copy one file into two locations

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
BalchBingham
Asked:
BalchBingham
  • 4
  • 3
3 Solutions
 
purplepomegraniteCommented:
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
 
purplepomegraniteCommented:
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
 
BalchBinghamAuthor Commented:
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
Industry Leaders: 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!

 
purplepomegraniteCommented:
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
 
BalchBinghamAuthor Commented:
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
 
BalchBinghamAuthor Commented:
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
 
BalchBinghamAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now