我正在尝试递归获取文件夹的子项。但是,该文件夹包含噪波文件和文件夹(实际上,这是Visual Studio项目文件夹)。
这是我所拥有的:
$root = Get-Item C:\Projects\MyProject
$allItems = Get-ChildItem $root -Recurse -exclude "**\pkgobj\*"
但是,$allItems
仍然包含与路径匹配的文件和文件夹。
我做错了什么?
更精确地说,我想同时获取文件夹和文件,但不获取指定的文件夹及其任何后代。
我也尝试过:
foreach($item in $allItems){
if($item.FullName -notmatch "pkgobj") {
Write-Host -ForegroundColor Green $item.FullName.Replace($root,'')
}
}
但是没有更多的成功