Avatar of support01
support01
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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.
Windows Batch

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
support01

ASKER
Excellent answer - just what i was looking for. Thank you for a real speedy response!
Bill Prew

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
oBdA

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Bill Prew

Got it.

~bp