假设我有5个文件
如何返回大小匹配的文件,因此新列表将包含F1,2,3,4但不包含F5?
要从我尝试的文件夹中获取这些文件:
var files = Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories)
.GroupBy(s1 => new FileInfo(s1).Length)
.SelectMany(grp => grp.Skip(1));
答案 0 :(得分:3)
一种方法是在群组计数中添加Where
:
var files = Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories)
.GroupBy(i=> new FileInfo(i).Length)
.Where(g=> g.Count() > 1)
.SelectMany(g => g);