Link to home
Create AccountLog in
Avatar of support01
support01Flag 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.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of support01

ASKER

Excellent answer - just what i was looking for. Thank you for a real speedy response!
Avatar of Bill Prew
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
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.
Got it.

~bp