Solved

Script to copy a folder to multiple folders

Posted on 2016-11-08
2
39 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

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

Title # Comments Views Activity
Robocopy syntax 10 116
Check Disk (CHKDSK) on all volumes and fix if needed. 8 178
robocopy 6 61
How to run multiple lines in a batch file 4 60
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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 …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

22 Experts available now in Live!

Get 1:1 Help Now