Powershell Power shell复制项目递归搜索选定文件,并仅将文件复制到目标文件夹

Powershell Power shell复制项目递归搜索选定文件,并仅将文件复制到目标文件夹,powershell,copy-item,Powershell,Copy Item,我想递归地获取可能存在于子文件夹中的特定文件,并将其复制到目标文件夹 我尝试执行以下命令: 获取子项“D:\Source Directory”|复制项-目的地“D:\Target Directory”-递归-筛选文件.doc 该命令复制的文件比获取的文件多 有更好的解决方案吗?Get ChildItem-Path“D:\Source Directory”-Recurse-Filter“file.doc”-file | Copy Item-Destination“D:\Target Directo

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

我尝试执行以下命令:

获取子项“D:\Source Directory”|复制项-目的地“D:\Target Directory”-递归-筛选文件.doc

该命令复制的文件比获取的文件多


有更好的解决方案吗?

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

您的-Flter和-Recurse都需要在Get ChildItem命令上,而不是在Copy Item命令上。您在尝试将多个同名文件复制到单个目录时也会遇到问题。我们需要重新思考一下。谢谢你的意见。获取子项-路径“D:\Source Directory”-递归-过滤器“file.doc”-文件|复制项-目标“D:\Target Directory”正在工作