Solved

Script to copy a folder to multiple folders

Posted on 2016-11-08
2
46 Views
Last Modified: 2016-11-09
Hi All,
I'd be grateful for your assistance please in creating a script to copy a folder to the application data folder of multiple users. The users have a homedrive located on server1 and I would like to copy a folder the application data folder within their homedrives.

I would like to copy a folder called Folder1 on \\server1\e$\Users\Students\ to \\server1\e$\Users\Students\2016Intake\%USERS%\Application Data\

I'm not sure of this is the most efficient method to do this but I have created a robocopy script to do this, however I cannot seem to find out how %USERS% can be represented with a wildcard. I have managed to export the names of the folders within 2016Intake into a txt file so maybe I could 'call' these.

If I user %USERNAME% as a wildcard the script will create a folder on \\server1\e$\Users\Students\2016Intake\ with my username.

My robocopy script so far looks like this:

robocopy "\\server1\e$\Users\Students\Folder1" "\\server1\e$\Users\Students\2016Intake\%USERS%\Application Data\" /MIR

I have tried replacing %USERS% with **, *.*, %%A etc but the script will only create a folder within the 2016Intake folder, whereas I am trying to copy the folder to the Application Data folder of these users.

Hopefully this makes sense.
Thanks in advance
0
Comment
Question by:itmtsn
2 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41879143
This should do the trick. It's in test mode and will only display the robocopy commands it would normally run. Remove the uppercase ECHO in front of line 6 to run it for real.
@echo off
setlocal
set Root=\\server1\e$\Users\Students\2016Intake
for /d %%a in ("%Root%\*.*") do (
	ECHO robocopy.exe "\\server1\e$\Users\Students\Folder1" "%%a\Application Data" /MIR
)

Open in new window

1
 

Author Closing Comment

by:itmtsn
ID: 41880037
This worked a treat, you're a legend, many thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
USB backup batch file help needed. 9 97
Windows Batch File - Count Down 4 70
User profile Size Report 3 72
Batch/VBScript : Disable Windows tasks 7 34
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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