batch file to copy a file to multiple computers by iteration?
26,923
Try this:
FOR /F "delims=" %%i IN (targets.txt) DO (
xcopy "D:\some.txt" "%%i"
)
targets.txt should contain entries like "\\10.124.66.72\texts" in each line
Author by
user755806
Updated on July 26, 2022Comments
-
user755806 almost 2 years
I have below batch script to copy file from my computer to many computers.
@echo off xcopy D:\some.txt \\10.124.66.72\texts xcopy D:\some.txt \\10.294.66.46\testfolder pause
In the script, i have mentioned all the other computer names/IPs. Now how can i keep other computer names in a separate text file and iterate them in batch file instead writing
xcopy
command many times? Or is it possible to mention list of computers, iterate through all and use single xcopy command? -
user755806 almost 10 yearsThanks MichaelS, do i need to give any delimiter between \10.124.66.72\texts and \10.294.66.46\testfolder ?
-
MichaelS almost 10 yearsNo, this command will read the file line by line. "Newline" is the default delimeter. If you want you can store several targets in one line and separate them using e.g. ";". In this case you would need the
delimeter
option. However I don't know how this could be useful unless you want to confuse yourself ;) -
foxidrive almost 10 years
tab
andspace
are the default delimiters when reading a file. If your folder names contain spaces then it will have to be modified. -
Lyth almost 10 years@foxidrive thanks for noticing that. Correct line will be:
FOR /F "tokens=*" %%i IN (targets.txt) DO (