public static void Delete()
        {
            FVLLog.AddLog("Delete part of history", null);
            IEnumerable <string> log = FVLLog.GetLog();
            string pathHistory       = @"E:\Универ\ООП\Лабы\History\FVLlogfile.txt";
            string day = DateTime.Today.ToString().Substring(0, 10);


            IEnumerable <string> ind = log.SkipWhile(n => !n.Contains(day));

            try
            {
                using (FileStream fileStream = File.Open(pathHistory, FileMode.Create, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(fileStream))
                    {
                        foreach (string n in ind)
                        {
                            Console.WriteLine($"{n}");
                            sw.WriteLine($"{n}");
                        }
                    }
                    fileStream.Close();
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(" - Error: " + e.Message);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
        public static void Show()
        {
            FVLLog.AddLog("Show history", null);
            IEnumerable <string> z = GetLog();

            foreach (string n in z)
            {
                Console.WriteLine($"{n}");
            }
        }
示例#3
0
 public static void RemoveFile(string path)
 {
     FVLLog.AddLog("Remove file", path);
     File.Delete(path);
     if (File.Exists(path))
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(" - Error: file was not removed");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
        public static void Show(int n)
        {
            FVLLog.AddLog($"Show first {n} linis in history", null);

            IEnumerable <string> z = GetLog().Take(n);

            foreach (string i in z)
            {
                Console.WriteLine($"{i}");
            }
        }
示例#5
0
 public static void RenameFile(string path, string name, string newName)
 {
     FVLLog.AddLog("Rename file ", path);
     CopyFile(path + name, path + newName);
     File.Delete(path + name);
     if ((File.Exists(path + name)) || !(File.Exists(path + newName)))
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(" - Error: file was not renamed");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
示例#6
0
 public static void MoveDirectory(string pathFrom, string pathIn)
 {
     FVLLog.AddLog($"Move direct from {pathFrom} in {pathIn}", null);
     pathIn += pathFrom.Substring(pathFrom.LastIndexOf(@"\") + 1) + @"\";
     CreateDir(@"E:\Универ\ООП\Лабы\FVLInspect\", null);
     Directory.Move(pathFrom, pathIn);
     if (Directory.Exists(pathFrom))
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(" - Error: file was not moved");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
示例#7
0
 public static void GetFileByPath(string path)
 {
     fI = new FileInfo(path);
     FVLLog.AddLog("Get file by path", path);
     if (fI.Exists)
     {
         Console.WriteLine($" - File name: {fI.Name} | Size: {fI.Length} | Time creating: {fI.CreationTime} | Путь: {fI.DirectoryName}");
     }
     else
     {
         Console.WriteLine("File is not exist");
     }
 }
示例#8
0
        public static void MoveFileExpansion(string pathFrom, string pathTo, string expan)
        {
            FVLLog.AddLog("Move file from " + pathFrom + " in " + pathTo, null);
            DirectoryInfo dir = new DirectoryInfo(pathFrom);

            FileInfo[] fileInfo = dir.GetFiles();
            foreach (var n in fileInfo)
            {
                if (n.Extension == expan)
                {
                    n.MoveTo(pathTo + n.Name);
                }
            }
        }
示例#9
0
 public static void CopyFilesWithExpan(string pathFrom, string pathIn, string expan)
 {
     FVLLog.AddLog("Copy files ", pathFrom);
     if (pathIn != null)
     {
         DirectoryInfo fileInfo = new DirectoryInfo(pathFrom);
         foreach (var n in fileInfo.GetFiles())
         {
             if (n.Name.Contains(expan))
             {
                 CopyFile(pathFrom + n.Name, pathIn + n.Name);
             }
         }
     }
 }
示例#10
0
        public static void CreateTxtFile(string path, string name, string info = "Filippov Vitaliy 2-8")
        {
            FVLLog.AddLog("Create text ", path);

            if (FVLFileInfo.CreateTxtFile(name, path, info))
            {
                Console.WriteLine("We create new file");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(" - Error: file was not created");
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
示例#11
0
 public static void UnZip(string path, string pathIn)
 {
     FVLLog.AddLog("Unzipped", path);
     try
     {
         ZipFile.ExtractToDirectory(path, pathIn);
         Console.WriteLine($"Unzipped successfully");
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($" - Error: {e.Message}");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
示例#12
0
 public static void CreateDir(string path, string name)
 {
     FVLLog.AddLog("Create dir", path);
     path += name;
     if (Directory.CreateDirectory(path).Exists)
     {
         Console.WriteLine("We create new direct");
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(" - Error: direction was not created");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
示例#13
0
 public static void ZipDir(string path, string pathIn, string name)
 {
     FVLLog.AddLog("Compression", null);
     pathIn = pathIn + @"\" + name + ".zip";
     try
     {
         ZipFile.CreateFromDirectory(path, pathIn);
         Console.WriteLine($"Size directory: {FVLDirInfo.SizeDir(path)}. Size of archive: {FVLFileInfo.FileSize(pathIn)}");
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($" - Error: {e.Message}");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
示例#14
0
 public static void CopyFile(string pathFrom, string pathIn)
 {
     FVLLog.AddLog("Copy file ", pathFrom);
     if (pathIn == null)
     {
         pathIn  = pathFrom.Remove(pathFrom.Length - 4, 4);
         pathIn += "_copyFile";
         pathIn += pathFrom.Substring(pathFrom.Length - 4);
     }
     File.Copy(pathFrom, pathIn);
     if (!File.Exists(pathIn))
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(" - Error: file was not copied");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
        public static void GetDirInfo(string path)
        {
            dirInfo = new DirectoryInfo(path);
            FVLLog.AddLog("Get dir info", path);
            if (dirInfo.Exists)
            {
                Console.WriteLine($" - Amount files: {dirInfo.GetFiles().Length}");
                Console.WriteLine($" - Time creating: {dirInfo.CreationTime}");
                Console.WriteLine($" - Amount dir: {dirInfo.GetDirectories().Length}");

                foreach (var n in dirInfo.GetDirectories())
                {
                    Console.WriteLine($" *Dir: {n.Name}");
                }
                Console.WriteLine($" - Path: {path}");
            }
            else
            {
                Console.WriteLine("Dir is not exist");
            }
        }
示例#16
0
 public static bool CreateTxtFile(string name, string path, string info)
 {
     FVLLog.AddLog("Create txt file  " + name + " in " + path, null);
     path += name + ".txt";
     //File.Create(path);
     using (StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8))
     {
         sw.WriteLine(info);
         sw.Close();
     }
     if (File.Exists(path))
     {
         Console.WriteLine("File successfully created");
         return(true);
     }
     else
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(" - Not complete");
         Console.ForegroundColor = ConsoleColor.Gray;
         return(false);
     }
 }
示例#17
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            FVLDiskInfo s = new FVLDiskInfo();

            s.ShowAllDriveInfo();
            s.GetFreeSpaceDisk(@"E:\");
            Console.ForegroundColor = ConsoleColor.Cyan;

            FVLFileInfo.GetFileByPath(@"E:\Универ\ООП\Лабы\Новая папка\param.txt");
            Console.ForegroundColor = ConsoleColor.Blue;

            FVLDirInfo.GetDirInfo(@"E:\Универ\ООП");
            Console.ForegroundColor = ConsoleColor.Cyan;

            FVLDirInfo.GetDirInfo(@"E:\Универ\ООП\Лабы");
            FVLFileManager.CreateDir(@"E:\Универ\ООП\Лабы\", "FVLInspect");
            FVLFileManager.CreateTxtFile(@"E:\Универ\ООП\Лабы\FVLInspect\", "fvldirinfo");
            FVLFileManager.CopyFile(@"E:\Универ\ООП\Лабы\FVLInspect\fvldirinfo.txt", null);
            FVLFileManager.RenameFile(@"E:\Универ\ООП\Лабы\FVLInspect\", "fvldirinfo_copyFile.txt", "renameFile.txt");
            FVLFileManager.DeleteFile(@"E:\Универ\ООП\Лабы\FVLInspect\fvldirinfo.txt");
            Console.ForegroundColor = ConsoleColor.Blue;

            FVLFileManager.CreateDir(@"E:\Универ\ООП\Лабы\", "FVLFiles");
            FVLFileManager.CopyFilesWithExpan(@"E:\Универ\ООП\Лабы\Новая папка\", @"E:\Универ\ООП\Лабы\FVLFiles\", ".txt");
            FVLFileManager.MoveDirectory(@"E:\Универ\ООП\Лабы\FVLFiles", @"E:\Универ\ООП\Лабы\FVLInspect\");
            Console.ForegroundColor = ConsoleColor.Cyan;
            //FVLLog.Delete();
            FVLFileManager.ZipDir(@"E:\Универ\ООП\Лабы\Новая папка", @"E:\Универ\ООП\Лабы", "zipArhive");
            FVLFileManager.UnZip(@"E:\Универ\ООП\Лабы\zipArhive.zip", @"E:\Универ\ООП\Лабы\Разархивировал сюда");
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            FVLLog.Show(15);
            Console.ForegroundColor = ConsoleColor.Cyan;
            FVLLog.SearchInfo("Create txt file");
            FVLLog.CountLog();
            Console.ReadKey();
        }
        public static void CountLog()
        {
            FVLLog.AddLog("Show count lines in history", null);

            Console.WriteLine($"Count lines in history: {GetLog().Count()}");
        }