使用"Where Object"命令树排除多个目录



我想知道如何在Where-Object中放置多个参数。使用树命令时,我希望排除多个文件夹。我试了好几种方法,但都没用。

tree /F src /a | Where-Object {$_ -notlike "*__pycache__" -or $_ -notlike "*migrations"} > tree.txt
tree /F src /a | Where-Object {$_ -notlike "*__pycache__|*migrations"} > tree.txt

这是一个逻辑问题&quot-或者-不象b〃;允许"-像";。做一些类似-不(这个或那个(的事情,这是一个很方便的成语。此外,|符号不是通配符,但您可以将其与-notmatch一起用作正则表达式。

'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

最新更新