1 using System; 2 using System.IO; 3 4 namespace _24._6_读取驱动器信息 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 var di = DriveInfo.GetDrives(); 11 12 foreach (var d in di) 13 { 14 try 15 { 16 Console.WriteLine(d.Name); 17 Console.WriteLine($"可用空间:{d.AvailableFreeSpace}"); 18 Console.WriteLine($"格式:{d.DriveFormat}"); 19 Console.WriteLine($"类型:{d.DriveType}"); 20 Console.WriteLine($"已准备好:{d.IsReady}"); 21 Console.WriteLine($"名称:{d.Name}"); 22 Console.WriteLine($"根目录:{d.RootDirectory}"); 23 Console.WriteLine($"总剩余空间:{d.TotalFreeSpace}"); 24 Console.WriteLine($"总空间:{d.TotalSize}"); 25 Console.WriteLine($"标签:{d.VolumeLabel}"); 26 Console.WriteLine(); 27 } 28 catch (Exception ex) 29 { 30 Console.WriteLine(ex.Message); 31 } 32 } 33 } 34 } 35 }
时间: 2024-10-10 06:16:08