/// <summary> /// Finds the duplicate files. /// </summary> /// <returns> /// The duplicate files in a list /// </returns> /// <param name='dirname'> /// Full path of the directory /// </param> public List<List<FileInfo>> FindDuplicateFiles(string dirname) { /// Populating the internal Files member by all the files in /// the directory `dirname' populateAllFilesRecursive (dirname); Strategies.StrategyProvider sp = new Strategies.StrategyProvider(); List<List<FileInfo>> fileNames = new List<List<FileInfo>> (); /// Iterating over all the files to check the duplicates for (int i=0; i< Files.Count; i++) { List<FileInfo> names = new List<FileInfo> (); FileInfo A = Files [i]; names.Add (A); for (int j=i+1; j< Files.Count; j++) { FileInfo B = Files [j]; /// Duplicate strategy calcualtes the probablity of /// duplicacy. DuplicateStrategy ds = new DuplicateStrategy (A, B, sp); int probablity = ds.GetDuplicateProbablity (); /// If there is a small chance we just consider to /// be a duplicate entry if (probablity > 0) { names.Add (B); } } /// if we get only a sigle copy of the current file then /// dont add it to the main output list if (names.Count > 1) { fileNames.Add (names); foreach(FileInfo name in names){ Files.Remove(name); } } } return fileNames; }
public DuplicateStrategy(FileInfo A, FileInfo B, StrategyProvider sp) { this.a = A; this.b = B; this.provider = sp; }