static void Main(string[] args) { Console.WriteLine("----------------------DVVDiskInfo-----------------------"); Console.WriteLine($"File system of D: {DVVDiskInfo.GetFileSystem("D")}"); Console.WriteLine($"Free space on D: {DVVDiskInfo.GetFreeSpace("D")} GB"); Console.WriteLine("Information about disk:"); Console.WriteLine(DVVDiskInfo.GetDisksInfo()); Console.WriteLine("-------------------- DVVFileInfo --------------------"); Console.WriteLine($"Hello.txt located at {DVVFileInfo.GetFullPath("Hello.txt")}"); Console.WriteLine($"{DVVFileInfo.GetMainFileInfo("Hello.txt")}"); Console.WriteLine($"{DVVFileInfo.GetCreationTime("Hello.txt")}"); Console.WriteLine(); Console.WriteLine("-------------------- DVVDirInfo --------------------"); Console.WriteLine($"Creation time: {DVVDirInfo.GetCreationTime("D:\\Battle.net")}"); Console.WriteLine($"Has {DVVDirInfo.GetNumberOfFiles("D:\\Battle.net")} files"); Console.WriteLine($"Parent of OOP: {DVVDirInfo.GetParents("D:\\Labs\\OOP")}"); Console.WriteLine($"Child of OOP:{DVVDirInfo.GetChild(@"D:\\Labs\\OOP")}"); Console.WriteLine(); DVVFileManager.WriteFilesAndFodlers("D"); DVVFileManager.CopyFilesByExtension("txt", @"D:\Labs\OOP\laba13\laba13\bin\Debug\DVVInspect"); DVVFileManager.ZipFolder(); Console.WriteLine("----------------------DVVlogfile-----------------------"); DVVLog.Upgrade(@"D:\Labs\OOP\laba13\laba13\bin\Debug\dvvlogfile.txt", DateTime.Now.Hour); DVVLog.Count(@"D:\Labs\OOP\laba13\laba13\bin\Debug\dvvlogfile.txt"); DVVLog.PrintInfo(@"D:\Labs\OOP\laba13\laba13\bin\Debug\dvvlogfile.txt"); }
public static string GetDisksInfo() { try { DriveInfo[] drivers = DriveInfo.GetDrives(); string info = $"Count of drivers: {DriveInfo.GetDrives().Length}\n"; foreach (var driveInfo in drivers) { try { info += $"Name: {driveInfo.Name} Free space: {driveInfo.AvailableFreeSpace / 1073741824} " + $"GB Total space: {driveInfo.TotalSize / 1073741824} GB " + $"Label: {driveInfo.VolumeLabel}\n"; DVVLog.AddNote("DVDDiskInfo", driveInfo.Name); //add log note } catch (IOException) { info += $"{driveInfo} not available.\n"; } } return(info); } catch (DriveNotFoundException) { return("Drive not found"); } }
public static string GetChild(string directoryPath) { try { DirectoryInfo info = new DirectoryInfo(directoryPath); DVVLog.AddNote("DVVDirInfo", info.FullName); return(Directory.GetDirectories(directoryPath).Count().ToString()); } catch (DirectoryNotFoundException) { return("Directory not found"); } }
public static string GetParents(string directoryPath) { try { DirectoryInfo info = new DirectoryInfo(directoryPath); DVVLog.AddNote("DVVDirInfo", info.FullName); //add log note return(info.Parent.ToString()); } catch (DirectoryNotFoundException) { return("Directory not found"); } }
public static string GetFileSystem(string diskName) { try { DriveInfo driveInfo = new DriveInfo(diskName); DVVLog.AddNote("DVDDiskInfo", driveInfo.Name); //add log note return(driveInfo.DriveFormat); } catch (DriveNotFoundException) { return("Drive not found"); } }
public static string GetFreeSpace(string diskName) { try { DriveInfo driveInfo = new DriveInfo(diskName); DVVLog.AddNote("DVVDiskInfo", driveInfo.Name); //add log return((driveInfo.AvailableFreeSpace / 1073741824).ToString()); } catch (DriveNotFoundException) { return("Drive not found"); } }
public static string GetCreationTime(string filename) { try { FileInfo file = new FileInfo(filename); DVVLog.AddNote("DVVFileInfo", file.FullName); //add log note return($"Creation time: {file.CreationTime}"); } catch (FileNotFoundException) { return("File not found"); throw; } }
public static string GetMainFileInfo(string filename) { try { FileInfo file = new FileInfo(filename); DVVLog.AddNote("DVVFileInfo", file.FullName); //add log note return($"File name: {file.Name} extension: {file.Extension} size: " + $"{file.Length / 1024} kb."); } catch (FileNotFoundException) { return("File not found"); throw; } }