0

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.

Community
  • 1
  • 1
user3762977
  • 651
  • 2
  • 15
  • 27
  • *However it doesn't seem to match anything.* How about file named `[A-Z]Something.htm`? – user4003407 Sep 05 '15 at 13:42
  • Well yeah it will match that. I've used the bracket syntax in JavaScript but it's clearly wrong here. This seemed to be implying that the syntax would work in powershell: https://technet.microsoft.com/en-us/library/Ee692793.aspx -- but I guess not. – user3762977 Sep 05 '15 at 13:50

1 Answers1

1

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

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206