public async static Task <Dictionary <string, List <string> > > ScanWithHashesAsync(string directoryPath) { var list = new List <HashedFileInfo>(); await RecursiveSearchLogic.RecursiveSearchAsync((path) => list.Add(new HashedFileInfo { Path = path, Hash = HashesCalculator.CalculateMD5(path), Size = (new System.IO.FileInfo(path)).Length }), new List <string>(), false, directoryPath); var hashedFilesGroups = list.GroupBy(hashFileInfo => hashFileInfo.Size).Where(group => group.Count() > 1).SelectMany(group => group.ToList()).GroupBy(hashedElement => hashedElement.Hash).Where(group => group.Count() > 1); var result = new Dictionary <string, List <string> >(); foreach (var group in hashedFilesGroups) { result[group.Key] = group.Select(element => element.Path).ToList(); } return(result); }
public static List <List <string> > Scan(string directoryPath) { using (var list = new HashedFilesList()) { var task = Task.Run(async() => { await RecursiveSearchLogic.RecursiveSearchAsync((path) => list.AddHashedFilePath(path, HashesCalculator.CalculateMD5(path)), new List <string>(), false, directoryPath); }); task.Wait(); return(FindDuplicateFilesInHashedFilesList(list)); } }