Reputation: 691
I wrote a Windows PowerShell script that's working, you can see the genesis of it in this thread, it watches a folder and runs a batch file when an .htm file is added to the folder.
That all works fine, but I'm now trying to filter which kinds of files trigger the script. From some things I've read, this should work to include only .htm files that start with A through Z:
$filter '[A-Z]*.htm'
However it doesn't seem to match anything.
I'm trying to exclude files like this:
~$abc.htm
What I have now matches all .htm files:
$filter = '*.htm'
and it works fine for that, but how do I exclude the files that start with ~$
, that is, non-alphabetical characters? Actually the ones I want to exclude always start with ~$
, if it's easier to pointedly exclude those.
Update:
Uh, well this page about PowerShell seemed to be recommending that syntax. It's clearly a different case but it seemed perhaps that meant that it's something that PS would recognize. I was recognizing that the syntax was wrong and asking what it should be, in other words, so downvoting seems a little weird. As I wrote, I'm trying to match
.htm files that start with A through Z
so clearly that's what I meant by not matching anything.
Upvotes: 0
Views: 2522
Reputation: 174465
It's not the Filter
parameter that supports character ranges, but rather the Path
parameter. Filter
only supports basic wildcard matching (*
and ?
)
Get-ChildItem -Path '.\[A-Z]*.htm'
Should do the trick
Upvotes: 1