In Linux, Bash supports negation syntax in glob pattern like [!abc]
for one character other than a
, b
, and c
.
I'm trying to find something similar in PowerShell.
In Supporting Wildcard Characters in Cmdlet Parameters, there is no description related to negation. Also, when test.txt
exists, I confirmed the following, which indicates that !
is not supported as negation syntax like Bash.
ls tes[!s].txt
returns nothing.ls tes[!t].txt
returns test.txt
Does PowerShell support negation syntax in glob pattern? If not, could you share some alternatives?
No, it does not (as you correctly deduced from such a feature not being documented, nor working).
An alternative are regular expressions, but you'd have to do the filtering yourself, then:
Get-ChildItem | Where-Object Name -match '^tes[^t]\.txt$'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With