获取指定目录下的所有特定格式命名的文件
string rootPath="D:\\data";
string searchPattern=$"data_*_{DateTime.Now.ToString("yyyyMMdd")}.txt";
List<string> files= Directory.GetFiles(rootPath, searchPattern, SearchOption.AllDirectories)
不同文件夹下的指定名称文件
string rootPath=@"D:\\data\\";
string date=DateTime.Now.ToString("yyyyMMdd");
var directories = Directory.EnumerateDirectories(rootPath, date, SearchOption.AllDirectories);
List<string> files = new List<string>();
string searchPattern=$"data_*_{DateTime.Now.ToString("yyyyMMdd")}.txt";
foreach (var directory in directories)
{
files.AddRange(Directory.GetFiles(directory, searchPattern, SearchOption.AllDirectories));
}