将bash中的查找和复制转换为Windows PowerShell中的某些

将bash中的查找和复制转换为Windows PowerShell中的某些,bash,powershell,find,Bash,Powershell,Find,我正在尝试将代码从bash转换为PowerShell,如下所示: 在bash中: find ./searchfolder -type f -name "something" | xargs cp -t ./destinationfolder 我的意思是“查找”命令查找 ./searchfolder/something ./searchfolder/0.15/something ./searchfolder/0.25/something 和“复制”命令复制新目录中的文件(保留文件夹结构)

我正在尝试将代码从bash转换为PowerShell,如下所示:

在bash中:

find ./searchfolder -type f -name "something" | xargs cp -t ./destinationfolder
我的意思是“查找”命令查找

./searchfolder/something

./searchfolder/0.15/something

./searchfolder/0.25/something 
和“复制”命令复制新目录中的文件(保留文件夹结构)


我该怎么做?提前感谢。

这是假设您正在C:\temp中查找文本文件并将其移动到C:

 Get-Childitem –Path C:\Temp -Recurse  -Include *.txt* | ForEach-Object {  mv $_.fullName  c:\ }

问候

在Copy Item命令上使用Filter参数怎么样?这可能会让你接近

cp ".\searchfolder" -Recurse -Filter "something" -Destination ".\destinationfolder"

cp
Copy Item
BTW的别名。

我假设这将是文件夹结构。Sourcefolder中只有一个子目录

SourceFolder
  --f1
    -test.txt
  --f2
    -test.txt
  --f3
    -other.txt
并复制文件名为test的文件夹

Destination
  --f1
    -test.txt
  --f2
    -test.txt
剧本

cd D:\Vincent\PSTesting

$Path = 'Searchfolder'

Get-ChildItem $Path -Recurse -Filter *Test*  -File | foreach {
    $SourceFolder = $_.Directory -replace "^.*$Path"
    Copy-Item -Path $Path\$SourceFolder -Destination "D:\Vincent\PSTesting\Destinationfolder\" -Verbose -Recurse

}

获取ChildItem以查找文件。。。和复制要复制的项Cmdlet…我无法一起收集。请指导我。这不是保留文件夹结构,只是移动到一个文件夹。脚本中不允许使用别名。你是说?解决方案?失败了。在循环中,代码创建searchfolder内容。比如,./destinationfolder/searchfolder/destinationfolder/searchfolder我再次测试了你的答案。事实上,你的答案是正确的。上一个问题是将destinationfolder放入searchfolder中引起的。那个是我愚蠢的错误。谢谢你们的回答。我的文件夹结构和你们说的一样。但是,我无法正确运行脚本。我尝试了不同的$Path,如D:\Vincent\PSTesting,PSTesting,但根据更改的不同,脚本不执行任何操作,或者在嵌套目录中的$SourceFolder上搜索,如D:\Vincent\PSTesting\D:\Vincent\PSTesting。我认为$Path应该从复制项中删除。我应该在$Path中写什么?我在哪里出错?谢谢。
cd D:\Vincent\PSTesting

$Path = 'Searchfolder'

Get-ChildItem $Path -Recurse -Filter *Test*  -File | foreach {
    $SourceFolder = $_.Directory -replace "^.*$Path"
    Copy-Item -Path $Path\$SourceFolder -Destination "D:\Vincent\PSTesting\Destinationfolder\" -Verbose -Recurse

}