如何使用Powershell搜索文件夹

时间:2021-07-26 00:32:06

I would like to search for a folder in a specific directory and subdirectorys.

我想搜索特定目录和子目录中的文件夹。

I tried googling it, but didn't really find any usefull examples.

我试过谷歌搜索它,但没有找到任何有用的例子。

1 个解决方案

#1


25  

Get-ChildItem C:\test -recurse | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match "keyword"}

I believe there's no dedicated cmdlet for searching files.

我相信没有用于搜索文件的专用cmdlet。

Edit in response to @Notorious comment: Since Powershell 3.0 this is much easier, since switches -Direcotry and -File were added to Get-ChildItem. So if you want it short you've got:

编辑以回应@Notorious评论:自从Powershell 3.0以来,这更容易,因为交换机-Direcotry和-File被添加到Get-ChildItem。所以如果你想要它很短,你就得到:

ls c:\test *key* -Recurse -Directory

With command alias and tab-completion for switches it's a snap. I just missed that the first time.

使用命令别名和开关的tab-completion,它很容易。我第一次错过了。

#1


25  

Get-ChildItem C:\test -recurse | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match "keyword"}

I believe there's no dedicated cmdlet for searching files.

我相信没有用于搜索文件的专用cmdlet。

Edit in response to @Notorious comment: Since Powershell 3.0 this is much easier, since switches -Direcotry and -File were added to Get-ChildItem. So if you want it short you've got:

编辑以回应@Notorious评论:自从Powershell 3.0以来,这更容易,因为交换机-Direcotry和-File被添加到Get-ChildItem。所以如果你想要它很短,你就得到:

ls c:\test *key* -Recurse -Directory

With command alias and tab-completion for switches it's a snap. I just missed that the first time.

使用命令别名和开关的tab-completion,它很容易。我第一次错过了。