コード例 #1
0
 /* get the folders in the current directory */
 private List <FolderFactory> _getSubfolderCollection()
 {
     /* have we done this before ? */
     if (_subfolderCollection == null)
     {
         _subfolderCollection = new List <FolderFactory>();
     }
     if (!_subfolderCollection.Any())
     {
         /* get the folders */
         string[] folders = Directory.GetDirectories(SourcePath, "*", System.IO.SearchOption.TopDirectoryOnly);
         /* process each folder */
         foreach (string folder in folders)
         {
             /* turn it in to a factory */
             FolderFactory ff = new FolderFactory(folder);
             /* add it to the subfolders */
             _subfolderCollection.Add(ff);
         }
     }
     return(_subfolderCollection);
 }
コード例 #2
0
        /** Button event */
        private void btnGo_Click(object sender, EventArgs e)
        {
            if (_SourceIsEmpty())
            {
                return;
            }

            /* setup the logfile */
            string logfile = "Unduplicator.log";

            using (StreamWriter outputFile = new StreamWriter(logfile))
            {
                /** Start logging */
                outputFile.WriteLine("Logging start");
                outputFile.WriteLine("=============");


                /* process the folders */
                outputFile.WriteLine("Getting all the folder content");
                List <FolderFactory> allFolders = new List <FolderFactory>();
                List <FileFactory>   allFiles   = new List <FileFactory>();
                foreach (string item in listBoxIn.Items)
                {
                    /* analyse the folder */
                    FolderFactory ff = new FolderFactory(item);
                    allFolders.Add(ff);
                    allFolders = ff.GetSubFolders(allFolders);

                    allFiles = ff.GetFiles(allFiles);
                }

                /* log how much we are processing */
                outputFile.WriteLine($"Processing {FileFactory.TotalFiles} files");
                outputFile.WriteLine($"Processing {FolderFactory.TotalFolders} folders");
                outputFile.WriteLine($"Processing {FileFactory.TotalBytes} bytes");

                /* start looking for duplicate files */
                foreach (FileFactory file in allFiles)
                {
                    file.GetDuplicates(allFiles);
                }

                /* look for identical folders */


                /* log identical files */
                outputFile.WriteLine("Identifying single duplicate files");
                outputFile.WriteLine("-------------------------");
                foreach (FileFactory file in allFiles)
                {
                    List <FileFactory> duplicates = file.GetDuplicates(new List <FileFactory>());
                    if (duplicates.Count > 0)
                    {
                        outputFile.WriteLine($"Not Moving {file.Source} To {file.Destination} ");

                        foreach (FileFactory duplicate in duplicates)
                        {
                            outputFile.WriteLine($"Moving {duplicate.Source} To {duplicate.Destination} ");
                        }
                        outputFile.WriteLine("-------------------------");
                    }
                }
            }
            /** show the log file */
            System.Diagnostics.Process.Start(logfile);
        }