Solved

Copy files to multiple locations

Posted on 2011-09-20
4
452 Views
Last Modified: 2012-05-12
Good morning all

I am looking for a script that allows me to copy the contents of one folder to a folder in multiple user areas

for example i have the following folders

c:\users\user1\templates
c:\users\user2\templates
c:\users\user3\templates

and I would like to copy the contents of c:\templates to these locations.  Folder names (user1, user2) in c:\users change on a daily basis .

Many thanks
Forsters
0
Comment
Question by:forsters
  • 3
4 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36565185
Hi, see if this works.

Regards,

Rob.
strSource = "C:\Templates"

If Right(strSource, 1) <> "\" Then strSource = strSource & "\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFolder In objFSO.GetFolder("C:\Users").SubFolders
	strTemplates = objFolder.Path & "\Templates\"
	If objFSO.FolderExists(strTemplates) = False Then objFSO.CreateFolder(strTemplates)
	objFSO.CopyFile strSource, strTemplates, True
Next

Open in new window

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36565189
Oops, try this.

Rob.
strSource = "C:\Templates"

If Right(strSource, 1) <> "\" Then strSource = strSource & "\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFolder In objFSO.GetFolder("C:\Users").SubFolders
	strTemplates = objFolder.Path & "\Templates\"
	If objFSO.FolderExists(strTemplates) = False Then objFSO.CreateFolder(strTemplates)
	objFSO.CopyFile strSource & "*", strTemplates, True
Next

Open in new window

0
 

Author Closing Comment

by:forsters
ID: 36565306
Wonderful works perfectly thanks the for the quick reply

Forsters
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36565828
No problem. Thanks for the grade.

Rob.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

813 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now