How do I use wildcards in C# to list down files contained in a selected folder?
You can do something like this:
string[] files = Directory.GetFiles(@"c:\myfolder", "*.txt", SearchOption.AllDirectories)
Use DirectoryInfo.GetFiles
using System.IO;
DirectoryInfo folder = new DirectoryInfo(@"C:\foo\bar");
if (folder.Exists) // else: Invalid folder!
{
FileInfo[] files = folder.GetFiles("*.xml");
foreach (FileInfo file in files)
{
DoSomething(file.FullName);
}
}
Directory.GetFiles is your friend here:
Directory.GetFiles(@"C:\Users\Me\Documents", "*.docx");
or, recursively:
Directory.GetFiles(
@"C:\Users\Me\Documents",
"*.docx",
SearchOption.AllDirectories);