c#快速获取超大文件夹文件名
枚举集合速度快:(10万个文件)
//by txwtech
IEnumerable<string> files2 = Directory.EnumerateFiles("d:\aa", "*.xml", SearchOption.TopDirectoryOnly);//过滤指定查询xml文件
慢:
var filename2= Directory.GetFiles("d:\aa", "*.xml", SearchOption.TopDirectoryOnly);
---------------------------------------------------------------------------------------------------------------
枚举转list
List<string> list_file_name = files2.ToList();//数据量大,转换则慢,
枚举集合查找指定文件
lambda表达式
List<string> lot_list= files2.Where(s=>s.Contains("Fa123456")).ToList();
LINQ语句:
var list_file_name = from str in files2
where str.Contains("Fa123456")
select str;
转List集合后查询速度快:
lambda表达式
//by txwtech
List<string> path_filted_list = list_file_name.Where(s => s.Contains("Fa123456")).ToList();