public static string GetDisksInfo() { try { DriveInfo[] drivers = DriveInfo.GetDrives(); string info = $"Number 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"; LVILog.AddNote("LVIDiskInfo", driveInfo.Name); //add log note } catch (IOException) { info += $"{driveInfo} not available.\n"; } } return(info); } catch (DriveNotFoundException) { return("Drive not found"); } }
public static string GetFreeSpace(string diskName) { try { DriveInfo driveInfo = new DriveInfo(diskName); LVILog.AddNote("LVIDiskInfo", driveInfo.Name); //add log return((driveInfo.AvailableFreeSpace / 1073741824).ToString()); } catch (DriveNotFoundException) { return("Drive not found"); } }
public static string GetFileSystem(string diskName) { try { DriveInfo driveInfo = new DriveInfo(diskName); LVILog.AddNote("LVIDiskInfo", driveInfo.Name); //add log note return(driveInfo.DriveFormat); } catch (DriveNotFoundException) { return("Drive not found"); } }
public static string GetParents(string directoryPath) { try { DirectoryInfo info = new DirectoryInfo(directoryPath); LVILog.AddNote("LVIDirInfo", info.FullName); //add log note return(info.Parent.ToString()); } catch (DirectoryNotFoundException) { return("Directory not found"); } }
public static string GetCreationTime(string filename) { try { FileInfo file = new FileInfo(filename); LVILog.AddNote("LVIFileInfo", 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); LVILog.AddNote("LVIFileInfo", 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; } }