コード例 #1
0
        public static void CreatePath()
        {
            if (!Directory.Exists(GlobalVar.pathToBackup))
            {
                Directory.CreateDirectory(GlobalVar.pathToBackup);
            }

            if (!Directory.Exists(GlobalVar.pathToCatalog))
            {
                Directory.CreateDirectory(GlobalVar.pathToCatalog);
            }

            DirectoryInfo txtFiles = new DirectoryInfo(GlobalVar.pathToCatalog);

            if (Directory.EnumerateDirectories(GlobalVar.pathToCatalog, "*", SearchOption.AllDirectories).Count() == 0 &&
                Directory.EnumerateFiles(GlobalVar.pathToCatalog, "*.*", SearchOption.AllDirectories).Count() == 0)
            {
                Console.WriteLine("Folder is empty.");
            }
            else
            {
                Console.WriteLine("Text files located in this folder and in its subfolders:");
                HierarchicalItem.getTreeStructure(txtFiles);
            }

            Watcher.MonitorDirectory(txtFiles);
        }
コード例 #2
0
        public static void RollbackChanges()
        {
            DirectoryInfo dirLog = new DirectoryInfo(GlobalVar.pathToBackup);

            HierarchicalItem.getTreeStructure(dirLog);

            string pathDate = CheckDatetime();

            try
            {
                DirectoryInfo dirToCatalog = new DirectoryInfo(GlobalVar.pathToCatalog);
                foreach (FileInfo file in dirToCatalog.EnumerateFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in dirToCatalog.EnumerateDirectories())
                {
                    dir.Delete(true);
                }
                foreach (var dir in Directory.GetDirectories(pathDate, "*", SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dir.Replace(pathDate, GlobalVar.pathToCatalog));
                }
                foreach (var item in Directory.GetFiles(pathDate, "*.*", SearchOption.AllDirectories))
                {
                    File.Copy(item, item.Replace(pathDate, GlobalVar.pathToCatalog), true);
                }

                Console.WriteLine("Rollback completed.");
            }
            catch (DirectoryNotFoundException dirEx)
            {
                Console.WriteLine("Directory not found: " + dirEx.Message);
                Console.WriteLine("Enter the correct date and time to roll back the changes.");
            }
        }