Batch File to Copy Files From All Users

Caldrumr

Distinguished
Jun 5, 2011
112
0
18,690
Good morning guys. I am trying to create a batch file, and I was hoping somebody with a bit more experience could help me clean it up. I have the basic idea, but I'm definitely not doing it correctly.
Basically, I want to create a batch that will copy all of the files in a particular folder from each user that exists on a system. So if the system has five profiles, it will copy the files from all users' roaming folders, if they exist.
Here is what I have now:

for /d %%u in (\\computer.domain\c$\users\*) do for %%x in (xml) do xcopy /s /c /i /y "\\computer.domain\c$\users\%%~nu\appdata\roaming\folder\subfolder\*.%%x" "X:\folder\subfolder"

Can someone point me in the right direction? Thanks!
 

Caldrumr

Distinguished
Jun 5, 2011
112
0
18,690
I changed the way this batch was running, and got it to do most of what I want:

for /d %%g in ("\\computer.domain\c$\users\*") do (
xcopy /c /i /y "%%g\AppData\Roaming\folder\subfolder\*.xml" "X:\folder\subfolder\%%g"
)

This copies what I need, but it creates the whole directory structure: computer, c$, users, user,file. Is there a way to get it to copy the file straight into a folder named after the computer, or computer, user?