You can use Linq, Directory.EnumerateFiles() and the Where() filter - this way you get only the files you need, the rest is filtered out.
Something like this should work:
Regex re = new Regex(@"^LOG\d+.bin$"); var logFiles = Directory.EnumerateFiles(somePath, "*.bin") .Where(f => !re.IsMatch(Path.GetFileName(f))) .ToList();
As stated, Directory.EnumerateFiles requires .NET 4.0. In addition, a slightly cleaner solution (at the cost of slightly more overhead) uses DirectoryInfo / EnumerateFiles() , which returns IEnumerable<FileInfo> , so you have direct access to the file name and extension without further analysis.
source share