【问题标题】:How to copy array of files (3,500) from directory A to Directory B如何将文件数组(3,500)从目录 A 复制到目录 B
【发布时间】:2020-01-24 17:47:55
【问题描述】:

我有 3,508 个不同名称的文件需要从目录 a 复制到目录 b。

试过了:

Copy-Item "C:\users\username\directory-a\file-1.jpeg,file-2.jpeg" -Destination "C:\users\username\directory-b\"

Powershell 会在文件分离时出错。

【问题讨论】:

  • 如果您需要复制文件夹中的所有文件,请尝试使用robocopy 'source_path' 'destination_path' /mir

标签: windows powershell command


【解决方案1】:

PowerShell 将采用文件名数组作为-Path-LiteralPath-Include 参数;但是,如果您要提供多个用逗号分隔的文件名,则必须将每个文件名单独引用 - 您的示例仅提供一个包含逗号的文件名。相反,使用

Copy-Item "C:\users\username\directory-a\file-1.jpeg","C:\users\username\directory-a\file-2.jpeg" -Destination "C:\users\username\directory-b\"

Copy-Item "C:\users\username\directory-a\*" -Include "file-1.jpeg","file-2.jpeg" -Destination "C:\users\username\directory-b\"

您可以将一个文件名数组的变量传递给我上面提到的任何参数,例如,

$files = (Get-Content C:\User\Me\List-of-files.txt)
Copy-Item -Path $Files -Destination D:\New-Folder

Copy-Item at Microsoft Docs 的文档没有说明这一点。

【讨论】:

    猜你喜欢
    • 2023-01-20
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多