如何以递归方式查找PowerShell中包含.hg文件夹的所有文件夹

Ola*_*døy 3 powershell mercurial

我试图在PowerShell中编写一个脚本来备份我们的Mercurial存储库集合.

我从这开始:

$repos=Get-ChildItem C:\hgrepos|Where-Object { $_.PSIsContainer }
Run Code Online (Sandbox Code Playgroud)

这将获得C:\ hgrepos下的第一级文件夹,这通常没问题,因为这是我们的存储库所在的位置.但是,存在子库.所以我需要递归.最重要的是,只应列出包含.hg子文件夹的文件夹.

man*_*lds 7

你可以使用-recurse标志Get-ChildItem

它将是这样的:

gci c:\hgrepos -recurse -include ".hg" | %{$_.Parent}
Run Code Online (Sandbox Code Playgroud)