Пример #1
0
        public List <string> syncArrays(string[] neededFiles, string rootPath) //PART 2.
        {
            LoadClientFiles r = new LoadClientFiles();

            List <string> myFiles     = new List <string>();
            List <string> failedFiles = new List <string>();

            Console.WriteLine($"\nSzükséges fileok száma: {neededFiles.Length} db");

            var cntr = 0;

            while (cntr < neededFiles.Length)
            {
                var name = Path.GetFileName(neededFiles[cntr]);

                string[] rootDirectory = Directory.GetFiles(rootPath, name, SearchOption.AllDirectories);

                try
                {
                    myFiles.Add(rootDirectory[0]);
                    cntr++;
                }
                catch (Exception)
                {
                    string fileToRemove = name;
                    neededFiles = neededFiles.Where(val => val != fileToRemove).ToArray();
                    Console.WriteLine($"A következő file nem található: {name}");
                    failedFiles.Add(name);
                }
            }


            if (failedFiles.Count != 0)
            {
                Console.WriteLine("\nA következő elemeket nem kerülnek másolásra:");
                foreach (var item in failedFiles)
                {
                    Console.WriteLine(item);
                }
            }
            return(myFiles);
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Add meg a főkönyvtár elérési útját:");
            string rootPath = Console.ReadLine();

            Console.WriteLine("\nAdd meg az ügyfél fileok elérési útját:");
            var clientPath = Console.ReadLine();


            try
            {
                var load = new LoadClientFiles();
                var sync = new SyncArrays();
                var copy = new CopyTheFiles();



                string[]      neededFiles = load.loadClientFiles(clientPath);       // PART 1.
                List <string> myFiles     = sync.syncArrays(neededFiles, rootPath); // PART 2.
                copy.copyTheFiles(myFiles, rootPath);                               // PART 3.
            }

            catch (FileNotFoundException) //Nem létező file
            {
                Console.WriteLine("\nHiba!");
            }

            catch (DirectoryNotFoundException) //Nem létező elérési út
            {
                Console.WriteLine($"\nHiba! Nem létező elérési út!");
            }

            catch (IOException)
            {
            }


            Console.ReadKey();
        }