First attempt at finding duplicate files. For now, and possible ever, this process will be a 'best effort' approach, so there will be false positives but this will most likely remain the case for the life of this program.
This commit is contained in:
@@ -272,9 +272,41 @@ namespace DataOrganizer
|
||||
return renames;
|
||||
}
|
||||
|
||||
public List<Duplicate> FindDuplicates(Folder topLevelFolder)
|
||||
{
|
||||
var duplicates = new Dictionary<string, Duplicate>();
|
||||
var files = topLevelFolder.GetAllFiles();
|
||||
var fileCount = 0;
|
||||
|
||||
fileCount = files.Count;
|
||||
|
||||
for(var i = 0; i < fileCount; i++)
|
||||
{
|
||||
var file = files[i];
|
||||
|
||||
//if (!duplicates.ContainsKey(file.FullPath)) duplicates.Add(file.FullPath, new Duplicate() { File = file, Duplicates = new List<FileSnapshot>() });
|
||||
|
||||
var dups = files.Where(x => x.Size == file.Size && x.FileId != file.FileId).ToList();
|
||||
var dupCount = dups.Count;
|
||||
|
||||
if(dupCount > 0)
|
||||
if (!duplicates.ContainsKey(file.FullPath)) duplicates.Add(file.FullPath, new Duplicate() { File = file, Duplicates = new List<FileSnapshot>() });
|
||||
|
||||
for (var j = 0; j < dupCount; j++)
|
||||
{
|
||||
var dup = dups[j];
|
||||
files.Remove(dup);
|
||||
duplicates[file.FullPath].Duplicates.Add(dup);
|
||||
fileCount--;
|
||||
}
|
||||
}
|
||||
|
||||
return duplicates.Values.ToList();
|
||||
}
|
||||
|
||||
public struct Duplicate
|
||||
{
|
||||
public DB.DBFileSnapshot File;
|
||||
public FileSnapshot File;
|
||||
public List<FileSnapshot> Duplicates;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user