Solved

Script to copy a folder to multiple folders

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

838 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