How do I use wildcards in C# to list down files contained in a selected folder?
You can use your own wildcards to limit search results. You can use a question mark (?) as a wildcard for a single character and an asterisk (*) as a wildcard for any number of characters. For example, *. pdf would return only files with the PDF extension.
Answer: Asterisk and question mark are 2 wildcard characters commonly used in searching information.
An asterisk is replaced by any number of characters in a filename. For example, ae* would match aegis, aerie, aeon, etc. if those files were in the same directory. You can use this to save typing for a single filename (for example, al* for alphabet.
Directory.GetFiles
is your friend here:
Directory.GetFiles(@"C:\Users\Me\Documents", "*.docx");
or, recursively:
Directory.GetFiles( @"C:\Users\Me\Documents", "*.docx", SearchOption.AllDirectories);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With