コード例 #1
0
        private static void GetFile(List <string> paths)
        {
            ComparableFolders folders = new ComparableFolders();

            foreach (string path in paths)
            {
                if (Directory.Exists(path))
                {
                    FolderContent folderContent = new FolderContent();

                    string[] dir = Directory.GetDirectories(path);
                    if (dir.Length > 0)
                    {
                        foreach (string d in dir)
                        {
                            string folderName = d.Replace($"{path}\\", null);
                            folderContent.PathSubDirectories.Add(folderName);
                        }
                    }
                    foreach (string s in Directory.GetFiles(path))
                    {
                        string fileName = s.Replace($"{path}\\", null);
                        folderContent.Files.Add(fileName);
                    }
                    folders.Comparables.Add(folderContent);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"{path} DOES NOT EXIST");
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                }
            }
            CompareFile(folders, paths);
        }
コード例 #2
0
        private static void CompareSubFolders(ComparableFolders folders, List <string> paths)
        {
            if (folders?.Comparables?.Count > 1)
            {
                FolderContent folderContent = new FolderContent();
                folderContent.PathSubDirectories = folders.Comparables[0].PathSubDirectories;

                bool complete = true;
                for (int i = 1; i < folders.Comparables.Count; i++)
                {
                    if (folderContent.PathSubDirectories.Count == folders.Comparables[i].PathSubDirectories.Count)
                    {
                        foreach (string path in folders.Comparables[i].PathSubDirectories)
                        {
                            if (!folderContent.PathSubDirectories.Contains(path))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine($"{paths[0]} and {paths[i]} Subfolders DO NOT MATCH. @(Different Subfolder = {paths[i]}\\{path})");
                                Console.ForegroundColor = ConsoleColor.DarkBlue;
                                complete = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Atleast one Subfolder is NOT IN BOTH PATHS.");
                        Console.ForegroundColor = ConsoleColor.DarkBlue;
                        complete = false;
                    }
                    if (complete)
                    {
                        Console.WriteLine($"{paths[0]} and {paths[i]} Subfolder Names matches.");
                        foreach (string s in folderContent.PathSubDirectories)
                        {
                            Console.WriteLine();
                            Console.WriteLine();
                            Console.WriteLine();
                            GetFile(new List <string>
                            {
                                $"{paths[0]}\\{s}",
                                $"{paths[i]}\\{s}"
                            });
                        }
                    }
                }
            }
        }
コード例 #3
0
        private static FolderContent GetAllFIlesnSubfolders(string path)
        {
            FolderContent output = new FolderContent();

            output.Path = path;
            foreach (string s in Directory.GetFiles(path))
            {
                output.Files.Add(s);
            }
            foreach (string s in Directory.GetDirectories(path))
            {
                output.PathSubDirectories.Add(s);
            }
            return(output);
        }
コード例 #4
0
 private static void CompareFile(ComparableFolders folders, List <string> paths)
 {
     if (folders?.Comparables?.Count > 1)
     {
         List <string> s             = new List <string>();
         FolderContent folderContent = new FolderContent();
         folderContent.Files = folders.Comparables[0].Files;
         for (int i = 1; i < folders.Comparables.Count; i++)
         {
             bool complete = true;
             if (folderContent.Files.Count == folders.Comparables[i].Files.Count)
             {
                 foreach (string file in folders.Comparables[i].Files)
                 {
                     if (!folderContent.Files.Contains(file))
                     {
                         Console.ForegroundColor = ConsoleColor.Red;
                         Console.WriteLine($"{paths[0]} and {paths[i]} FILES DO NOT MATCH. @(Different File = {file})");
                         Console.ForegroundColor = ConsoleColor.DarkBlue;
                         complete = false;
                         //break;
                     }
                 }
             }
             else
             {
                 Console.ForegroundColor = ConsoleColor.Red;
                 Console.WriteLine($"{paths[0]} and {paths[i]} FILES DO NOT MATCH. The number of files contained in each are not equal");
                 Console.ForegroundColor = ConsoleColor.DarkBlue;
                 complete = false;
             }
             if (complete)
             {
                 Console.WriteLine($"{paths[0]} and {paths[i]} Files match.");
                 CompareSubFolders(folders, paths);
             }
         }
     }
 }