The NameFilter class can be used to filter files and folders according to their names.
When using NameFilter classes, by default, case sensitivity is not enforced. In order to enforce case sensitivity, a greater-than symbol (>) must be used as the first character of the string. For example:
Process all files that have the TXT extension. Since, by default, the FilterScope enumeration is set to File and we are using "*.txt" as the filter, there is no need to implicitly set the FilterScope enumeration in the constructor of the NameFilter class.
Since we are using a basic string filter, the NameFilter class is used by default, therefore we can omit the creation of a new NameFilter class and simply use a basic filter.
Process all files that have either the TXT or EXE extension.
It is possible to simplify the above example by using the pipe (|) character to separate the two strings. The pipe character servers the same purpose as the OrFilter class and removes the necessity of creating two instances of the NameFilter class and regrouping them within an OrFilter class.
Here are more complex examples
Do you only want to target specific types of folder items? Use the FilterScope enumeration in the constructor of the NameFilter class.