public void DiskInfo() { string tolog = ""; Console.WriteLine("\tDiskInfo"); DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo drive in drives) { tolog = ""; tolog += $"\tName: {drive.Name}" + '\n'; tolog += $"\tType: {drive.DriveType}" + '\n'; if (drive.IsReady) { tolog += $"\tFormat: {drive.DriveFormat}" + '\n'; tolog += "\tFreeSpace: available " + String.Format("{0:F3}", (double)drive.AvailableFreeSpace / 1048576 / 1024) + " GB, total " + String.Format("{0:F3}", (double)drive.TotalFreeSpace / 1048576 / 1024) + " GB" + '\n'; tolog += $"\tCapacity: " + String.Format("{0:F3}", (double)drive.TotalSize / 1048576 / 1024) + " GB" + '\n'; } Console.WriteLine(tolog); SDELog.WriteSome("DiskInfo", tolog.Substring(0, tolog.Length - 2)); } }
public void ShowInfoAboutFilesAndDirectories(string dirWay) { Directory.CreateDirectory(inspectDirWay); FileInfo fileInfo = new FileInfo(fileDirInfoWay); using (FileStream fstream = new FileStream(fileDirInfoWay, FileMode.Create)) { StreamWriter sw = new StreamWriter(fstream); if (Directory.Exists(inspectDirWay)) { sw.WriteLine("Files:"); string[] files = Directory.GetFiles(dirWay); foreach (string s in files) { FileInfo f = new FileInfo(s); sw.WriteLine(f.FullName); } sw.WriteLine(); sw.WriteLine("Folders"); string[] dirs = Directory.GetDirectories(dirWay); foreach (string s in dirs) { DirectoryInfo d = new DirectoryInfo(s); sw.WriteLine(d.FullName); } } sw.Close(); } fileInfo.CopyTo(fileDirInfoWay + "copy.txt", true); fileInfo.Delete(); SDELog.WriteSome("Show info about files and dir", inspectDirWay); }
static void Main(string[] args) { try { SDEDiskInfo diskInfo = new SDEDiskInfo(); diskInfo.DiskInfo(); SDEFileInfo file = new SDEFileInfo(); file.FileData("Lab13.exe"); SDEDirInfo dirInfo = new SDEDirInfo(); dirInfo.DirInfo(@"../../../../labs"); SDEFileManager fileManager = new SDEFileManager(); fileManager.ShowInfoAboutFilesAndDirectories(@"../../../../labs"); fileManager.CopyFiles(@"../../../../labs", "txt"); fileManager.Archive(@"SDEInspect\SDEFiles"); fileManager.ClearFiles(); SDELog.CountAndDelete(); } catch (Exception ex) { Console.WriteLine("Error:" + ex.Message); } Console.ReadKey(); }
public void ClearFiles() { Console.WriteLine("Clear Files"); Console.ReadKey(); Directory.Delete(inspectDirWay, true); Directory.Delete("Unzip", true); File.Delete("Files.zip"); SDELog.WriteSome("Clear files", "final"); }
public void Archive(string dirWay) { using (ZipFile zip = new ZipFile()) { //zip.Password = "******"; zip.AddItem(dirWay); zip.Save("Files.zip"); } using (ZipFile zip = ZipFile.Read("Files.zip")) { Directory.CreateDirectory("Unzip"); zip.ExtractAll("Unzip/", ExtractExistingFileAction.OverwriteSilently); } SDELog.WriteSome("Zip and unzip", "Unzip"); }
public void CopyFiles(string dirWay, string expansion) { Directory.CreateDirectory(FilesDirWay); string[] files2 = Directory.GetFiles(dirWay); foreach (string s in files2) { FileInfo fileInfo = new FileInfo(s); if (fileInfo.Extension == '.' + expansion) { File.Copy(s, FilesDirWay + '/' + fileInfo.Name, true); } } Directory.Move(FilesDirWay, inspectDirWay + '/' + FilesDirWay); SDELog.WriteSome("Copy files with some expansion", inspectDirWay + '/' + FilesDirWay); }
public void FileData(string fileWay) { string tolog = ""; Console.WriteLine("\tFileInfo"); FileInfo fileInfo = new FileInfo(fileWay); if (fileInfo.Exists) { tolog += $"\tFull way : {fileInfo.DirectoryName}" + '\n' + $"\tName: {fileInfo.Name}\n" + $"\tCapacity: {fileInfo.Length} Bytes\n\tExtension: {fileInfo.Extension}\n\tCreationTime: {fileInfo.CreationTime}"; Console.WriteLine(tolog); SDELog.WriteSome("FileInfo", tolog); } else { SDELog.WriteSome("FileInfo", "This file doesn't exists"); Console.WriteLine("This file doesn't exists"); } }
public void DirInfo(string dirWay) { string tolog = ""; Console.WriteLine("\n\tDirInfo"); if (Directory.Exists(dirWay)) { string[] files = Directory.GetFiles(dirWay); int countFiles = 0; foreach (string s in files) { countFiles++; } DirectoryInfo dirInfo = new DirectoryInfo(dirWay); tolog += $"\tFull way: {dirInfo.FullName}" + '\n' + $"\tCreation Time: {dirInfo.CreationTime}" + '\n' + $"\tCount Of Files: {countFiles}" + '\n'; string[] dirs = Directory.GetDirectories(dirWay); int countSubDir = 0; foreach (string s in dirs) { countSubDir++; } tolog += $"\tCount Of Sub Directories: {countSubDir}" + '\n' + $"\tParents: {dirInfo.Parent}" + '\n'; Console.WriteLine(tolog); SDELog.WriteSome("DirInfo", tolog.Substring(0, tolog.Length - 2)); } else { SDELog.WriteSome("DirInfo", "This directory doesn't exists"); Console.WriteLine("This directory doesn't exists"); } }