C# -- 使用 DriveInfo 获取磁盘驱动器信息
1. 代码实现
class Program { static void Main(string[] args) { GetComputerDisk(); Console.ReadKey(); } private static void GetComputerDisk() { DriveInfo[] LocalDrive = DriveInfo.GetDrives(); for (int i = 0; i < LocalDrive.Length; i++) { Console.WriteLine("------------------------------------------"); Console.WriteLine(string.Format("驱动器名称:{0}", LocalDrive[i].Name)); Console.WriteLine(string.Format("存储空间大小:{0}字节", LocalDrive[i].TotalSize)); Console.WriteLine(string.Format("可用空间大小:{0}字节", LocalDrive[i].AvailableFreeSpace)); Console.WriteLine(string.Format("可用空闲空间:{0}字节", LocalDrive[i].TotalFreeSpace)); Console.WriteLine(string.Format("文件系统:{0}", LocalDrive[i].DriveFormat)); Console.WriteLine(string.Format("驱动器类型:{0}", LocalDrive[i].DriveType)); Console.WriteLine(string.Format("驱动器IsReady:{0}", LocalDrive[i].IsReady)); Console.WriteLine(string.Format("驱动器的根目录:{0}", LocalDrive[i].RootDirectory)); Console.WriteLine(string.Format("驱动器卷标:{0}", LocalDrive[i].VolumeLabel)); } } }
2. 运行结果: