8

Get-Help Get-ChildItem displays -Filter parameter, with displayed wording "Specifies a filter in the provider's format or language". That language differs between what Powershell calls "providers", and file system is declared as one of them. But I have not found any syntax descriptions on file system provider's filter syntax. Any help?

Vesper
  • 18,599
  • 6
  • 39
  • 61

1 Answers1

6

The filter syntax supported by the FileSystem provider is sparsely (if it all) documented, probably because there's nothing much to say.

In short, it only supports simple wildcard matching as you know it from Windows XP-era Search:

Any file with an extension:

*.*

Any file with the .txt extension:

*.txt

Partial wildcard matching:

*something*.txt

Single-character matching (matches myfile1.jpg but not myfile01.jpg):

myfile?.*

Simple character sets (this matches bear and beer):

be[ae]r

Simple character ranges (this matches filea.txt, fileb.txt and filec.txt):

file[a-c].txt

Note: It only supports a single expression per filter, so this is illegal:

*.jpg|*.txt
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Apparently I'm pretty stupid, I've noticed that `[-Filter]` is an optional and position-based parameter, and I'm accustomed to `dir *.txt` where `*.txt` is actually not path but filter. So there's pretty much nothing but name to be filtered via `Get-ChildItem` prior to getting a `FileInfo` object set. Sad but true. – Vesper Jul 30 '15 at 08:09
  • Indeed. In case you want multiple filters though, you could use `-Include` - supports same basic wildcard syntax, but accepts an array of string values: `-Include "??id*.jpg","*.txt"` – Mathias R. Jessen Jul 30 '15 at 08:12
  • I'm also reading that PS5 (or maybe PS1+, but it's hidden) allows `-attributes` for additional filtering. Sadly, no filters by date, and I was really wondering if there's a better way than piping discovered files to `Where-Object`. Thanks again. – Vesper Jul 30 '15 at 08:16
  • [Here is](https://stackoverflow.com/a/12914655/48639) a useful info on the `-Filter` parameter – Stoinov Oct 19 '18 at 11:04