Headhunter Xamd
Headhunter Xamd

Reputation: 606

exact functionality of the * wildcard in searchpatterns

I have an folder with more than 150 files, I want to collect a list with all the ones which contain a certain keyword. The keyword can be at the beginning or somewhere in the middle. "*.xml" catches all the xml files.

Here is my question when I do this "*partkey*.xml" does this catch all the files which contain the substring?
for example: string[] files = Directory.GetFiles("thepathtothefolder", "*key*.xml");
Do I get my expected output?

Upvotes: 0

Views: 56

Answers (2)

Mithrandir
Mithrandir

Reputation: 25357

You might want to look it up here. There you will find the "exact" description of the meaning for the wildcard characters * and ?. It is the same meaning the * caracter had since MS DOS times, it stands for 'zero or more' characters.

The line

string[] files = Directory.GetFiles("thepathtothefolder", "*key*.xml");

will give you an array with all the filenames that contain thre characters 'key'.

Upvotes: 2

Andrea Cattaneo
Andrea Cattaneo

Reputation: 588

Yes. With search pattern "*partkey*.xml" you will get all the files that ends with ".xml" and contains string "partkey"

Output example:
123partkey123.xml
456partkey456.xml

Upvotes: 0

Related Questions