예제 #1
0
        public static void BackUpSystem(int input, string sourceDirectory, string copy)
        {
            if (input == 1)
            {
                DateTime date = DateTime.Now;

                //string logs = copy + date.Date + date.TimeOfDay;

                string logFolder = copy + date.Day + "."
                                   + date.Month + "." + date.Year + "_" + date.Hour + "h"
                                   + date.Minute + "m" + date.Second + "s";

                Loker Loker = new Loker(sourceDirectory, copy);
                Loker.Start();
            }
            else if (input == 2)
            {
                Console.WriteLine("Enter the time for which you whant to back up");
                Console.WriteLine("Format: day.month.year + _ + hours + h + minutes + m + seconds + s");

                string[]      txtList = Directory.GetFiles(sourceDirectory, "*.txt");
                var           tmp     = Console.ReadLine();
                DirectoryInfo copyDir = new DirectoryInfo(copy + tmp);

                if (copyDir.Exists)
                {
                    try
                    {
                        foreach (var item in txtList)
                        {
                            File.Delete(item);
                        }
                    }
                    catch (System.IO.IOException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    DirectoryInfo sourceDir = new DirectoryInfo(sourceDirectory);
                    foreach (DirectoryInfo dir in sourceDir.GetDirectories())
                    {
                        try
                        {
                            dir.Delete(true);
                        }
                        catch (IOException e)
                        {
                            throw new Exception(e.Message);
                        }
                    }

                    DirectoryCopy(copyDir.ToString(), sourceDirectory, true);
                    Console.WriteLine("Backup completed successfully");
                }
                else
                {
                    Console.WriteLine("Can't back up for this time :(");
                }
            }
        }
예제 #2
0
 static void Main()
 {
     Loker.StartTask();
 }