Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the FileSystem provider filter syntax?

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?

like image 555
Vesper Avatar asked Jul 30 '15 07:07

Vesper


People also ask

What is File system provider?

A file system provider is a concrete implementation of this class that implements the abstract methods defined by this class. A provider is identified by a URI scheme . The default provider is identified by the URI scheme "file".

What is the use of File provider in PowerShell?

The PowerShell FileSystem provider lets you get, add, change, clear, and delete files and directories in PowerShell. The FileSystem drives are a hierarchical namespace containing the directories and files on your computer. A FileSystem drive can be a logical or physical drive, directory, or mapped network share.


1 Answers

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
like image 164
Mathias R. Jessen Avatar answered Oct 02 '22 14:10

Mathias R. Jessen