windows 批处理文件通过迭代将文件复制到多台计算机?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24931935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
batch file to copy a file to multiple computers by iteration?
提问by user755806
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?
在脚本中,我提到了所有其他计算机名称/IP。现在如何将其他计算机名称保存在单独的文本文件中并在批处理文件中迭代它们而不是xcopy
多次编写命令?或者是否可以提及计算机列表,遍历所有并使用单个 xcopy 命令?
回答by MichaelS
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
target.txt 应该在每一行中包含像“\\10.124.66.72\texts”这样的条目