C# -- 使用 DriveInfo 獲取磁碟驅動器信息 1. 代碼實現 2. 運行結果: ...
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. 運行結果: