Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I search for a list of files using wildcard

Tags:

c#

wildcard

How do I use wildcards in C# to list down files contained in a selected folder?

like image 739
yeeen Avatar asked Oct 18 '09 12:10

yeeen


People also ask

How do you use wildcards to search files and folders?

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.

Which wildcards are used for searching for files?

Answer: Asterisk and question mark are 2 wildcard characters commonly used in searching information.

How do you use wildcards in file names?

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.


1 Answers

Directory.GetFiles is your friend here:

Directory.GetFiles(@"C:\Users\Me\Documents", "*.docx"); 

or, recursively:

Directory.GetFiles(     @"C:\Users\Me\Documents",     "*.docx",     SearchOption.AllDirectories); 
like image 191
Joey Avatar answered Sep 26 '22 23:09

Joey