In C# how can I search through a Folder and its Subfolders to find files that match a string value. My string value could be \"ABC123\" and a matching file might be ABC123_
From memory so may need tweaking
class Test
{
ArrayList matches = new ArrayList();
void Start()
{
string dir = @"C:\";
string pattern = "ABC";
FindFiles(dir, pattern);
}
void FindFiles(string path, string pattern)
{
foreach(string file in Directory.GetFiles(path))
{
if( file.Contains(pattern) )
{
matches.Add(file);
}
}
foreach(string directory in Directory.GetDirectories(path))
{
FindFiles(directory, pattern);
}
}
}