简体   繁体   English

如何将源路径列表中定义的文件复制到 cmd 或 powershell 中的 output 路径列表中?

[英]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.

相关问题 在Powershell中对路径列表进行排序 - Sorting a list of paths in Powershell 将列表连接到路径的末尾 - Powershell - Concatenate a list to the end of paths - Powershell Powershell-将目录路径列表传递到FOR Loop-将结果输出到CSV - Powershell - Pass list of directory paths to FOR Loop - Output results to CSV 如何使用 PowerShell 将本地文件和路径复制到网络共享? - How to copy local files AND PATHS to network share using PowerShell? Powershell-如何将文件列表复制到目标 - Powershell - How copy list of files to destination 如何使用列表将多个子目录中的源文件匹配,然后使用Powershell复制到目标 - How to match source files in multiple subdirectories with a list and then copy to destination using powershell 如何在PowerShell上处理路径? - How to deal with paths on PowerShell? 从 CMD 以路径为参数调用 Powershell 脚本 - Calling Powershell script from CMD with paths as parameters 如何在 PowerShell 中列出文件夹中的所有文件(执行 cmd 的 `dir /A`)? - How to list all files in a folder (do cmd's `dir /A`) in PowerShell? 使用Win cmd.exe列出仅显示文件名(无路径)的文件夹及其子文件夹中的所有文件的命令 - Command to list all files in a folder and its sub-folders showing filenames only (no paths) using Win cmd.exe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM