Batch file copy to multiple folders

paulmarsh used Ask the Experts™
I need to copy a Default User profile directory to all users home directory. There are nearly 2000 users listed in nt user manager. I want to copy from c:\profile\default user to \\server\%username%\
Is there a way of including a variable that will equal the name of the users home directory in a batch file?  Or is there an easier way?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
i assume you have some specific information in the default user directory that you want applied to each user without having to manually add files to each directory. so why don't you write a login script that copys this contents of c:\profile\default user to the \\server\%username%

if you share the default directory as readonly it might look like:


then you could do this:

copy \\server\default\*.* \\server\%username%\*.* /x

i realize this won't get every single user right off the .bat, but hopefully within a couple of weeks they will all be done. i think the /x will only allow the contents to be copied once. if not you can create a file at the end of the script and run a check for that file at the beginning of the script.

i don't know if it'll work, let me know if you try it.
Most things like this get run through login scripts, and leave room for contention (in use) and timespan to get all of them. With that many users, I wonder also on confidence level of them even using a login script, or if many simply access a shared file and do not need to process that script?

You answered your own question pretty much. Use a logon script to execute a copy command.

Script looks like this:

copy c:\<dir>\file.txt \\<servername>\%username%\file.txt

That's it. This is assuming of course that the user directory is the same as their username. If there are other characters in there (ie $) just put them after the %username% variable.

Hope this helps.

Just read your post c30keith...didn't mean to repeat exactly what you just said!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial