static void Main(string[] args)
        {
            try
            {
                DDADiskInfo.DiskFreeSpace("D");
                DDADiskInfo.FileSystemInfo();
                DDADiskInfo.AllDisksInfo();

                DDAFileInfo file = new DDAFileInfo(@"C:\Users\dimde\OneDrive\Рабочий стол\arp-ping.exe");
                file.FileInfo();
                DDADirInfo dir = new DDADirInfo(@"C:\Users\dimde\OneDrive\Рабочий стол\ООТП\OOPLab13\OOPLab13");
                dir.DirInfo();
                DDAFileManager.TaskA("D:\\");
                DDAFileManager.TaskB(@"C:\Users\dimde\OneDrive\Рабочий стол\ЯП\Лабараторные\ЛР17_18(14,15)\LPLab14\LPLab14", ".cpp");
                DDAFileManager.TaskC();

                DDALog.FindByDay("13");
                DDALog.FindByTime("16", "17");
                DDALog.FindByWord("DDADirInfo.DirInfo, directory:");
                Console.WriteLine($"Records written in log file: {DDALog.CountRecords()}");
                DDALog.ClearToLastHour();
                DDALog.Close();
            }
            catch (Exception exc)
            {
                Console.WriteLine($"Exception: {exc.Message} at {exc.Source}");
            }
        }
        public static void TaskB(string path, string extension)
        {
            DDALog.WriteHead($"DDAFileManager.TaskB files with extension {extension} at {path}");

            DirectoryInfo source = new DirectoryInfo(path);

            if (Directory.Exists(path + "DDAFiles"))
            {
                Directory.Delete(path + "DDAFiles");
            }
            source.CreateSubdirectory("DDAFiles");
            string path_to_inspect = @"C:\Users\dimde\OneDrive\Рабочий стол\ООТП\OOPLab13\OOPLab13\DDAInspect\DDAFiles";

            foreach (FileInfo item in source.GetFiles())
            {
                if (item.Extension == extension)
                {
                    item.CopyTo(source + "\\DDAFiles\\" + item.Name, true);
                }
            }

            if (!Directory.Exists(path_to_inspect))
            {
                Directory.Move(path + "\\DDAfiles", path_to_inspect);
            }
        }
        public static void TaskA(string disk_name)
        {
            DDALog.WriteHead($"DDAFileManager.TaskA files and subdirictories in disk {disk_name}");

            string[] dirs  = Directory.GetDirectories(disk_name);
            string[] files = Directory.GetFiles(disk_name);

            string        path      = @"C:\Users\dimde\OneDrive\Рабочий стол\ООТП\OOPLab13\OOPLab13";
            DirectoryInfo directory = new DirectoryInfo(path);

            directory.CreateSubdirectory("DDAInspect");

            FileInfo file = new FileInfo(directory.FullName + "\\DDAInspect\\DDAdirinfo.txt");

            using (StreamWriter sw = new StreamWriter(file.FullName))
            {
                sw.WriteLine("Subdirectories:");
                foreach (string s in dirs)
                {
                    sw.WriteLine(s);
                }
                sw.WriteLine("Files:");
                foreach (string s in files)
                {
                    sw.WriteLine(s);
                }
            }
            File.Copy(file.FullName, file.DirectoryName + "\\dirinfo_copy.txt", true);
            file.Delete();
        }
 public static void FileSystemInfo()
 {
     DDALog.WriteHead("DDADiskInfo.FileSystemInfo");
     foreach (DriveInfo disk in AllDisk)
     {
         DDALog.WriteMessage($"Drive name: {disk.Name}, drive type: {disk.DriveType}");
     }
     DDALog.WriteMessage("\n-----------------------------------------------------------------------------------\n");
 }
Ejemplo n.º 5
0
 public void DirInfo()
 {
     DDALog.WriteHead($"DDADirInfo.DirInfo, directory: {dir.Name}");
     if (dir.Exists)
     {
         DDALog.WriteMessage($"Full path: {dir.FullName}");
         DDALog.WriteMessage($"Number of files: {dir.GetFiles().Length}");
         DDALog.WriteMessage($"Time creation: {dir.CreationTime}");
         DDALog.WriteMessage($"Number of subdirectories: {dir.GetDirectories().Length}");
         DDALog.WriteMessage($"List of parent directories of subdirectories: {ParentList()}");
         ParentList();
         DDALog.WriteMessage("-----------------------------------------------------------------------------------\n");
     }
 }
 public void FileInfo()
 {
     DDALog.WriteHead($"DDAFileInfo.FileInfo, file: {fileInfo.Name}");
     if (fileInfo.Exists)
     {
         DDALog.WriteMessage($"File path: {fileInfo.FullName}");
         DDALog.WriteMessage($"Size: {fileInfo.Length} bytes");
         DDALog.WriteMessage($"Extension: {fileInfo.Extension}");
         DDALog.WriteMessage($"Name: {fileInfo.Name}");
         DDALog.WriteMessage($"File path: {fileInfo.FullName}");
         DDALog.WriteMessage($"Creation time: {fileInfo.CreationTime}");
         DDALog.WriteMessage($"Last change time: {fileInfo.LastWriteTime}");
     }
     DDALog.WriteMessage("-----------------------------------------------------------------------------------\n");
 }
 public static void AllDisksInfo()
 {
     DDALog.WriteHead("DDADiskInfo.AllDisksInfo");
     foreach (DriveInfo disk in AllDisk)
     {
         DDALog.WriteMessage($"Name disk:{disk.Name}");
         if (disk.IsReady)
         {
             DDALog.WriteMessage($"Total size: {disk.TotalSize / 1024 / 1024 / 1024} GB");
             DDALog.WriteMessage($"Free space: {disk.TotalFreeSpace / 1024 / 1024 / 1024} GB");
             DDALog.WriteMessage($"FileSystem:{disk.RootDirectory}");
             DDALog.WriteMessage($"VolumeLabel:{disk.VolumeLabel}");
             DDALog.WriteMessage($"DriveType:{disk.DriveType}\n");
         }
     }
     DDALog.WriteMessage("-----------------------------------------------------------------------------------\n");
 }
 public static void DiskFreeSpace(string name)
 {
     DDALog.WriteHead("DDADiskInfo.DiskFreeSpace :\\" + name);
     DDALog.WriteMessage(name);
     name = name + ":\\";
     DDALog.WriteMessage(name);
     foreach (DriveInfo disk in AllDisk)
     {
         if (disk.Name == name)
         {
             DDALog.WriteMessage($"Name disk:{disk.Name}");
             if (disk.IsReady)
             {
                 DDALog.WriteMessage($"Free space: {disk.TotalFreeSpace / 1024 / 1024 / 1024} GB\n");
             }
         }
     }
     DDALog.WriteMessage("-----------------------------------------------------------------------------------\n");
 }
        public static void TaskC()
        {
            DDALog.WriteHead("DDAFileManager.TaskC archieving");
            string path = @"C:\Users\dimde\OneDrive\Рабочий стол\ООТП\OOPLab13\OOPLab13\DDAInspect\DDAFiles";

            DirectoryInfo directory = new DirectoryInfo(path);

            if (!File.Exists(@"C:\Users\dimde\OneDrive\Рабочий стол\ООТП\OOPLab13\OOPLab13\DDAInspect\DDAFiles.zip"))
            {
                ZipFile.CreateFromDirectory(directory.FullName, directory.FullName + ".zip");
            }

            using (ZipArchive zip = new ZipArchive(File.Open(directory.FullName + ".zip", FileMode.Open)))
            {
                DirectoryInfo buf = new DirectoryInfo(@"C:\Users\dimde\OneDrive\Рабочий стол\ООТП\OOPLab13\OOPLab13\DDAInspect");
                foreach (ZipArchiveEntry x in zip.Entries)
                {
                    x.ExtractToFile(buf.FullName + '\\' + x.Name, true);
                }
            }
        }