How to search a folder or file under a directory using wildcard in C#?
The Directory class packed with System.IO namespace has a method called GetDirectories() which can be used to search a folder.
This little code snippet will help us to search a folder using wildcard characters in GetDirectories() method.
To list all folders that start with lazyload word,
string dirs = Directory.GetDirectories(@"E:\bala\Technicals\Samples", "lazyload*", SearchOption.AllDirectories);
foreach (string dir in dirs)
Response.Write(dir + "<br>");
To list all files that start with the word User,
string files = Directory.GetFiles(@"E:\bala\Technicals\Samples", "User*", SearchOption.AllDirectories);
Response.Write("<b>List of file</b><br>");
foreach (string file in files)
Response.Write(file + "<br>");
Include System.IO namespace for the above code snippets to work.