30
6
I'm trying to get child items of a folder recursively. However the folder contains noise files and folder (actually, this is a Visual Studio project folder).
Here what I have:
$root = Get-Item C:\Projects\MyProject
$allItems = Get-ChildItem $root -Recurse -exclude "**\pkgobj\*"
However, $allItems still contains files and folder matching the paths.
What I did wrong?
To be more precise, I want to get both folders and files, but not the specified folder, and any of its descendant.
I also tried:
foreach($item in $allItems){
if($item.FullName -notmatch "pkgobj") {
Write-Host -ForegroundColor Green $item.FullName.Replace($root,'')
}
}
But no more success
1However, if you want to exclude large directories due to performance (like node_modules), this won't help since it will still recursively check everything and filter afterwards. – Pluc – 2019-02-26T15:50:14.200
What about this ? Get-ChildItem -Exclude exclude_dir | foreach { Get-ChildItem -Path $_ -Include *.include -Recurse -Exclude *.excludefile | foreach { echo $_ } } – NN_ – 2019-05-20T18:18:10.553