[英]How to copy files defined in a list of source paths to a list of output paths in cmd or powershell?
i have a list of source files and a list of destination files in two variables, all delimited with spaces:我有两个变量中的源文件列表和目标文件列表,所有变量都用空格分隔:
$srcFiles = C:/srcpath1/srcfile1 C:/srcpath2/srcfile2 ...
$dstFiles = C:/dstpath1/srcfile1 C:dstpath2/srcfile2 ...
how can I copy all src files to all output locations using either cmd or powershell?如何使用 cmd 或 powershell 将所有 src 文件复制到所有 output 位置?
Assuming you have two arrays that are ordered appropriately, you can do something like the below:假设您有两个正确订购的 arrays,您可以执行以下操作:
param(
$srcFiles = @("$PSScriptRoot\src\file1.txt", "$PSScriptRoot\src\file2.txt"),
$destFiles = @("$PSScriptRoot\dest\file1.txt", "$PSScriptRoot\dest\file2.txt")
)
for ($i = 0; $i -lt $srcFiles.Length; $i++) {
Copy-Item -Path $srcFiles[$i] -Destination $destFiles[$i]
}
Personally, I might use a hash table for this instead of the two arrays.就个人而言,我可能会为此使用 hash 表而不是两个 arrays。
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.