Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCopy one directory to different destination

Tags:

batch-file

Just want to ask, can you copy one entire directory to multiple destination?

Example 

Source:        "c:\MyProject\Sample\*.*"
Destination:   "\\Computer1\Sample\"
               "\\Computer2\Sample\"
               "\\Computer3\Sample\"
               "\\Computer4\Sample\"

I used this syntax to copy the entire directory

Example

Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer1\Sample\"

Now, Is there a way to loop through the following destination..? Do you have any suggestion on i can accomplish this scenario..?

Hope to hear from you soon..

Thanks,

Link

like image 502
Link Avatar asked Mar 12 '12 11:03

Link


2 Answers

for %%D in (
  "\\Computer1\Sample\"
  "\\Computer2\Sample\"
  "\\Computer3\Sample\"
  "\\Computer4\Sample\"
) do Xcopy /E /Y "c:\MyProject\Sample*.*" "%%D"

The above assumes you are using a batch file. If run from the command line, then use %D instead of %%D. Also, the entire command can be put on one line, with spaces as path delimiters.

like image 102
dbenham Avatar answered Sep 21 '22 22:09

dbenham


You can write a batch file that has multiple xcopies to achieve this

Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer1\Sample\"
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer2\Sample\"
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer3\Sample\"
Xcopy /E /Y "c:\MyProject\Sample*.*" "\Computer4\Sample\"
like image 39
Vijay EK Avatar answered Sep 17 '22 22:09

Vijay EK