用linq方式在一组文件夹及两组文件夹中查找重复文件,并可移动或删除重复文件
在10万级别以上文件中试用,效果良好
一:在一组文件夹中查询重复文件
代码:
//已读取完毕的文件信息及md5的entity
List<entity_FileWithMd5> arr_FilesMd5_Tmp = new List<entity_FileWithMd5>();
//....
//要查询文件数,
i_CheckFilesCount = arr_FilesMd5_Tmp.Count;
//linq查询,重复值>1
List<IGrouping<string, entity_FileWithMd5>> lstSameFile = arr_FilesMd5_Tmp.GroupBy(a => a.str_MD5)
.Where(g => g.Count() > 1).ToList();
//序号
int iIndex = 0;
//entity
entity_FileWithMd5WithCorrespond firstObj = null;
//循环(为了找出该文件对应的重复文件)
lstSameFile.ForEach(a =>
{
//序号
iIndex = 0;
//entity
firstObj = new entity_FileWithMd5WithCorrespond();
//a {System.Linq.Lookup<string,entity_FileWithMd5>.Grouping}
// IGrouping<string,entity_FileWithMd5>
var lstTmp = a.ToList();
//
lstTmp.ForEach(b =>
{
if (iIndex == 0)
{
firstObj.str_FILE_NAME_CORRESPOND = b.str_FILE_NA