Copying User Data - Copy files where source folder <user>names differ from destination

I regularly need to copy user data from a long list of user paths for example:
from d:\usershares\Joe Bloggs to \\server\users\Co-JBloggs
from d:\usershares\John Doe to \\server\users\Co-JDoe
etc. etc...
(the folder names don't necessarily follow a convention.)

- I have a table with lists of source and destination folders.
- All user subfolders fall under the same top level folder.
- I do not need or want to copy permissions.
- I would prefer to achieve this using a proprietary Microsoft tool like Robocopy which I usually use for similar jobs. I cannot see a way to do this without creating separate jobs files for each user. I have a list of 80 names to copy on this occasion and would prefer not to have 80 separate jobs running concurrently.

Does anyone know a way to cleanly achieve this?

Examples would be excellent, if you care to include.

Thank you.
support01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You won't get around the 80 different copies, but the good news is, you can just pack it into a loop, one after another.
Assuming you have a tab-delimited text file with <Source folder><Tab><Target Folder>, all you need is the following script.
If the delim differs, change it in line 7.
The script is currently in test mode and will only display the folders it would normally copy.
Remove the /L ("list only") from the RCOptions variable to copy for real.
Remove  /nfl (no file list), /ndl (no directory list) /njs (no job summary) as required, and add whatever other robocopy options you need.
@echo off
setlocal enabledelayedexpansion

set InputFile=C:\Temp\list.txt
set RCOptions=/e /r:0 /L /nfl /ndl /njs
REM Set the delim char between 'delim=' and the closing '"'
for /f "tokens=1,2 delims=	" %%a in ('type "%InputFile%"') do (
	set Source=%%~a
	set Target=%%~b
	if "!Source:~-1!"=="\" set Source=!Source!\
	if "!Target:~-1!"=="\" set Target=!Target!\
	robocopy.exe "!Source!" "!Target!" %RCOptions%
)

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
support01Author Commented:
Excellent answer - just what i was looking for. Thank you for a real speedy response!
0
Bill PrewCommented:
I think these two lines:

      if "!Source:~-1!"=="\" set Source=!Source!\
      if "!Target:~-1!"=="\" set Target=!Target!\


should be:

      if NOT "!Source:~-1!"=="\" set Source=!Source!\
      if NOT "!Target:~-1!"=="\" set Target=!Target!\


yes?

~bp
0
oBdACommented:
Nope.
If a folder argument for robocopy is enclosed in quotes, and the last character of the folder string happens to be a backslash, then this backslash will escape the double quote, and robocopy will obviously not find the designated folder.
So if the last character happens to be a backslash, it needs to be escaped with an additional backslash.
And you can't just remove a trailing backslash, because you might encounter a root drive, in which case the copy will use D:<current working directory in D> when actually C:\ was meant. Shouldn't happen in this case, but I prefer not to rely on that.
0
Bill PrewCommented:
Got it.

~bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.