Solved

Script to copy a folder to multiple folders

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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