I'm looking to create a batch file copy a folder from \\server\folder\subdirectory to \\server\users\username\folder. I don't want to have hundreds of lines for all the users. I there a simpler wild card or variable I can use.
I have this so far and it works if I input each username one by one.
robocopy "\\server\folder\subdirectory" "\\server\users\%username%\folder" /e /v /dcopy:t /copy:dat /r:1 /w:1 /A-:SHA /XA:H
copy "\\server\folder\subdirectory\*.docx" "\\server\users\%username%\folder2" 2 1 Answer
Based on the code you provided I believe this is the simplest method of accomplishing what you want:
@echo off
set "src=\\server\folder\subdirectory"
set "des=\\server\users"
for /d %%A in (%des%\*) do ( robocopy "%src%" "%%A\folder" /e copy "%src%\*.docx" "%%A\folder2"
)I like using variables to reduce the amount of things you need to change and to make lines that would potentially be full of paths a bit easier to digest. Above you will see I set variables for both your source (src) and destination (des) paths, and used those in a simple for loop.
For any subfolders of the destination (/d in %des%\*) assign them to our parameter %%A, then use that parameter in both your robocopy and copy scripts. You'll see I didn't include all of your robocopy flags, but that was to make the example as simple as possible. Hopefully this works out for you or whoever else stumbles upon this question.