コード例 #1
0
        public string CalculateKey(DuplicateFile file)
        {
            StringBuilder toReturn = new StringBuilder();

            if (DupCriteriaMD5)
            {
                toReturn.Append(file.MD5);
            }
            if (DupCriteriaName)
            {
                toReturn.Append(file.FileName);
            }
            if (DupCriteriaSize)
            {
                toReturn.Append(file.FileSize.ToString());
            }

            return(toReturn.ToString());
        }
コード例 #2
0
        private void ScanFileInfo(string folder)
        {
            var dirInfo = new DirectoryInfo(folder);

            foreach (var file in dirInfo.GetFiles())
            {
                try
                {
                    var item = new DuplicateFile
                    {
                        FileName    = file.Name,
                        FullPath    = file.FullName,
                        FileSize    = file.Length,
                        FileChanged = file.LastWriteTime,
                        FileCreated = file.CreationTime
                    };
                    if (_Criteria.DupCriteriaMD5)
                    {
                        item.MD5 = GetFileMD5(item.FullPath);
                    }

                    string key = _Criteria.CalculateKey(item);

                    if (AllFiles.ContainsKey(key))
                    {
                        AllFiles[key].Add(item);
                    }
                    else
                    {
                        AllFiles.Add(key, new List <DuplicateFile>()
                        {
                            item
                        });
                    }

                    if (FileAdded != null)
                    {
                        FileAdded(item.FullPath);
                    }

                    var fileFolder = Path.GetDirectoryName(item.FullPath);

                    if (DuplicateByFolder.ContainsKey(fileFolder))
                    {
                        DuplicateByFolder[fileFolder].Add(item);
                    }
                    else
                    {
                        DuplicateByFolder.Add(fileFolder, new List <DuplicateFile>()
                        {
                            item
                        });
                    }
                }
                catch (Exception ex)
                {
                }
            }

            foreach (var directory in dirInfo.GetDirectories())
            {
                ScanFileInfo(directory.FullName);
            }
        }