Reputation: 871
I would like to know how to put multiple arguments in the Where-Object
.
I would like to exclude multiple folders when I use the tree command.
I tried several ways but none worked.
tree /F src /a | Where-Object {$_ -notlike "*__pycache__" -or $_ -notlike "*migrations"} > tree.txt
tree /F src /a | Where-Object {$_ -notlike "*__pycache__|*migrations"} > tree.txt
Upvotes: 0
Views: 648
Reputation: 27606
This is a logic problem. "-or -notlike b" allows "-like a". Do something like -not (this -or that), a handy idiom to know. Also, the |
symbol is not a wildcard character, but you can use it with -notmatch as regex.
'a','b' | ? { $_ -notlike '*a*' -or $_ -notlike '*b*' }
a
b
'a','b' | ? { $_ -notlike '*a*|*b*' }
a
b
'a','b' | ? { -not ($_ -like '*a*' -or $_ -like '*b*' ) }
# no result
'a','b' | ? { $_ -notmatch 'a|b' }
# no result
Upvotes: 1