Solved

Copy files to multiple locations

Posted on 2011-09-20
4
456 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
[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
  • 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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