Ejemplo n.º 1
0
        /// <summary>
        /// checks all files in a directory tree for size (and optionally name) equality
        /// </summary>
        /// <param name="pfad">root folder of directory tree</param>
        /// <param name="modus">comparison type</param>
        /// <returns>a list of possible duplicates</returns>
        public IEnumerable <IDublette> Sammle_Kandidaten(string pfad, Vergleichsmodi modus)
        {
            var             files     = Directory.GetFiles(pfad, "*", System.IO.SearchOption.AllDirectories).Select(t => new FileInfo(t)).ToList();
            List <Dublette> dubletten = new List <Dublette>();

            int counter = 0;

            files.ForEach(file =>
            {
                IEnumerable <FileInfo> targetFiles;
                switch (modus)
                {
                case Vergleichsmodi.Größe_und_Name:
                    targetFiles = files.Where(t => t.Name == file.Name && t.Length == file.Length);
                    break;

                case Vergleichsmodi.Größe:
                    targetFiles = files.Where(t => t.Length == file.Length);
                    break;

                default:
                    throw new NotImplementedException();
                }
                //check if any target files were found AND first target file does not belong to any set (if it does, all target files do)
                if (targetFiles.Any() && !dubletten.SelectMany(t => t.Fileinfos).Any(t => t.FullName == targetFiles.FirstOrDefault().FullName))
                {
                    dubletten.Add(new Dublette(targetFiles.Select(t => t.FullName)));
                }

                counter++;
                this.ProgressReport?.Invoke(this, $"Candidate check finished (file {counter} of {files.Count})");
            });
            return(dubletten);
        }
Ejemplo n.º 2
0
 public IEnumerable <IDublette> Sammle_Kandidaten(string pfad, Vergleichsmodi modus)
 {
     throw new NotImplementedException();
 }