I'm trying to list all the files with .rar or .zip file type.
I tried regular expressions like the ones you can find in the online regex helpers, but none of those seems to work.
Maybe the problem is trying to do this directly into the cmd/powershell instead of a script ?
dir *./(zip|rar)/
The expected result would be something like: file1.rar file2.rar file3.zip
In Powershell, dir
is an alias for Get-ChildItem
. You cannot use a regex directly. Powershell is interpretting your regex as a wildcard.
As noted in the other answers and in the Get-ChildItem documentation, you can to use a comma to separate your search terms. dir *.zip,*.rar
, which is an alias for
Get-ChildItem -path *.zip,*.rar
If you'd like to use a regex, you need to assign the result of Get-ChildItem
to a variable and then use -match
.
> $dir = Get-ChildItem
> $dir -match "\.(zip|rar)$"
Or use parentheses to turn it into a one-liner:
(Get-ChildItem) -match "\.(zip|rar)$"
get-childitem -path takes an array. Not regex, but an array of wildcards that serve the same purpose.
dir *.zip,*.rar
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