Mats codemix

Mats codemix

A little c#, a litte .NET and throw in some c++ and you get a nice Spaghetti

Mats codemix RSS Feed
 
 
 
 

Powershelll tips - Filter on container

Say you want to recurse a diretory tree and show just the directories.

Yo can write

ls C:\ -rec | %{if ($_.PSIsContainer) { $_ }} | %{$_.Fullname}

Add a little filter function

1 function FilterContainer()
2 {
3     process
4     {
5         %{if ($_.PSIsContainer) { $_ }}
6     }
7 }

Which reduces the first line to

ls C:\ -rec | FilterContainer | %{$_.Fullname}

Leave a Reply