-1

I am looking for a quick way to copy data from one location to multiple user profile locations on the server share. The only change in the destination path is the username.

I want to target specific users, and those user ID are in a text file.

Can I loop though this list replacing the username in the path and make the copy?

I can do this the long way either manual copy, or create hundreds of lines, and changing the username for each copy using the below command

XCOPY C:\Shortcuts\* \\Server\Share\%USERNAME%\Profile\Favorites\Shortcuts /s /I

Many thanks

user3364233
  • 105
  • 2
  • 13
  • I wouldn't copy the shortcut and create it instead. See here: http://superuser.com/questions/392061/how-to-make-a-shortcut-from-cmd – Marged Oct 15 '15 at 12:02
  • And at least part of your question seems to be a duplicate of http://stackoverflow.com/questions/206114/batch-files-how-to-read-a-file – Marged Oct 15 '15 at 12:14
  • Cheers horse. I'll review those other threads. I did review other threads before posting up but I will review the threads you have posted and see if I can put together a solution. Cheers the -1! – user3364233 Oct 15 '15 at 13:29

1 Answers1

1

Sounds easy. Let's assume you want to copy X:\someDir to Y:\%USERNAME%\someDir using any user name listed in a text file (user_list.txt or something) as %USERNAME%.

FOR /F %%U IN (user_list.txt) DO (
    XCOPY X:\someDir Y:\%%U\someDir /E /Y /I
)

This should work as long as your user names don't contain special characters.

MichaelS
  • 5,941
  • 6
  • 31
  • 46
  • Thank you MichaelS. I gave this a go but I get an error %UU not expected at this time. I'll check out the other threads that the horse put up before coming back – user3364233 Oct 15 '15 at 13:27
  • @user3364233 `%%u` will only work when used in a batch, in case you try this directly on the command line you will have to write `%u` – Marged Oct 15 '15 at 13:31
  • Thank you Marged. My batch file did not like the %uu however using just %u from the command line worked fine and I am happy with this to get the job done FOR /F %U IN (C:\LOOPTEST\USERLIST.TXT) DO xcopy c:\looptest\test\* c:\looptest\%U\favorites /s /I – user3364233 Oct 15 '15 at 14:30
  • @user3364233 It's not %UU, it's %%U! Inside a bat you should use %%U and %U from the command line. – MichaelS Oct 19 '15 at 10:21
  • %UU was a typo above. Just checked and what i use direct from a command line does not work in batch file. No bother lad, your solution worked for me and I achieved what i set out to do – user3364233 Oct 20 '15 at 11:16