Solved

Copy files to multiple locations

Posted on 2011-09-20
4
449 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

20 Experts available now in Live!

Get 1:1 Help Now