【问题标题】:Power shell copy item search on selected files recursively and copy only file to destination folderPower shell 复制项目以递归方式搜索选定文件并将仅文件复制到目标文件夹
【发布时间】:2021-03-25 13:07:14
【问题描述】:

我想递归地获取可能存在于子文件夹中的特定文件并将其复制到目标文件夹。

我尝试执行以下命令:

Get-ChildItem "D:\Source Directory" | Copy-Item -Destination "D:\Target Directory" -Recurse -filter file.doc

该命令复制的文件多于获取的文件。

有更好的解决方案吗?

【问题讨论】:

  • 您的 -Flter 和 -Recurse 都需要在 Get-ChildItem 命令上,而不是在 Copy-Item 命令上。您在尝试将多个同名文件复制到单个目录时也会遇到问题。需要重新思考一下。
  • 感谢您的意见。 Get-ChildItem -Path "D:\Source Directory" -Recurse -Filter "file.doc" -File | Copy-Item -Destination "D:\Target Directory" 正在工作

标签: powershell copy-item


【解决方案1】:

Get-ChildItem -Path "D:\Source Directory" -Recurse -Filter "file.doc" -File | Copy-Item -Destination "D:\Target Directory"

【讨论】:

    猜你喜欢
    • 2018-03-05
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 2014-10-04
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多