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.

2
  • However it doesn't seem to match anything. How about file named [A-Z]Something.htm? Commented Sep 5, 2015 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: technet.microsoft.com/en-us/library/Ee692793.aspx -- but I guess not. Commented Sep 5, 2015 at 13:50

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.