Is there an easy way (not using loops) to apply -like with more than one pattern to one string?
so
"c:\myfile.txt" -like "*.dat","*.txt"
should return $true
"c:\myfile.dat" -like "*.dat","*.txt"
should return $true
"c:\myfile.doc" -like ".dat",".txt"
should return $false
I don't think so. You could use regular expression:
"c:\myfile.txt" -match '^.+\.(dat|txt)$'
UPDATE
Make a regex pattern from input that contains a wildcard patterns:
PS> $or = '"*.dat","*.txt","*.foo"' -replace '"|\*\.' -replace ',','|'
PS> $pattern = '^.+({0})$' -f $or
PS> $pattern
^.+(dat|txt|foo)$
$string -match $pattern
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