在 Windows 命令行上将文件复制到网络计算机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12523520/
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
Copy files to network computers on windows command line
提问by Jay
I am trying to create a script on Windows which when run on an admin PC:
我正在尝试在 Windows 上创建一个脚本,该脚本在管理 PC 上运行时:
- Copies a folder from the admin PC into a group of network PCs by specifying the ip address / range
- For each destination PC, Navigate into the folder and run another script file.
- 通过指定ip地址/范围将一个文件夹从管理PC复制到一组网络PC中
- 对于每个目标 PC,导航到文件夹并运行另一个脚本文件。
Using the method described by seanyboy here:
使用seanyboy描述的方法,在这里:
net use \{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \{dest-machine}\{destfolder}
I'm not sure on how i can write a 'for' loop to go through each 'dest-machine' and perform step 2. Any ideas would be greatly appreciated.
我不确定如何编写“for”循环来遍历每个“dest-machine”并执行第 2 步。任何想法将不胜感激。
回答by Tilo
check Robocopy:
检查 Robocopy:
ROBOCOPY \\server-source\c$\VMExports\ C:\VMExports\ /E /COPY:DAT
ROBOCOPY \\server-source\c$\VMExports\ C:\VMExports\ /E /COPY:DAT
make sure you check what robocopy parameter you want. this is just an example.
type robocopy /?
in a comandline/powershell on your windows system.
确保您检查了您想要的 robocopy 参数。这只是一个例子。robocopy /?
在 Windows 系统上输入命令行/powershell。
回答by Anvesh Yalamarthy
Below command will work in command prompt:
下面的命令将在命令提示符下工作:
copy c:\folder\file.ext \dest-machine\destfolder /Z /Y
To Copy all files:
复制所有文件:
copy c:\folder\*.* \dest-machine\destfolder /Z /Y
回答by Maximus
Why for
? What do you want to iterate? Try this.
为什么for
?你想迭代什么?尝试这个。
call :cpy pc-name-1
call :cpy pc-name-2
...
:cpy
net use \%1\{destfolder} {password} /user:{username}
copy {file} \%1\{destfolder}
goto :EOF