0

I would like to list all directories named bin and obj that are anywhere in the current directory tree but without descending into the node_modules directory.

I've tried ls . -Recurse -Include bin,obj -Exclude node_modules but that doesn't work and still includes things inside node_modules.

What's the proper way to do this?

George Mauer
  • 117,483
  • 131
  • 382
  • 612
  • @TessellatingHeckler yes except the accepted answer doesn't really answer the question does it? Lots of ways that could not match properly. – George Mauer Jul 25 '16 at 15:55
  • It answers that `-exclude` won't work for this use case, that the way forward is to use the pipeline and create a filter that fits your use case. It's not exactly a copy-and-paste answer for your conditions. I can only really imagine it failing completely if your current directory is already inside a `node_modules` folder, presumably you know if that is the case. Instead, this discussion is more thorough: http://stackoverflow.com/questions/8024103/how-to-retrieve-a-recursive-directory-and-file-list-from-powershell-excluding-so – TessellatingHeckler Jul 25 '16 at 16:45
  • 1
    Except for the file mask, `Where-Object` is always more reliable than `Get-ChildItem -Include` and `-Exclude` options are. I avoid both `-Include` and `-Exclude` entirely. They're too flaky with too many caveats, and never behave like I expect. Similarly, I avoid `-Recurse` on `Copy-Item` and `Remove-Item` in favor of `Get-ChildItem -Recurse`. Yes, it sucks. Microsoft will fix it as soon as they fix the version numbers in the path for the PowerShell.exe. – Bacon Bits Jul 25 '16 at 17:15

0 Answers0