如何使用 C# 獲取完整的驅動器資訊?
作業系統驅動器資訊包括。
Drive Name Volume Label Free Space Total Size Drive Format Drive Type
要獲取有關驅動器的上述資訊,請嘗試執行以下程式碼 -
示例
using System.IO; using System; class Program { static void Main() { DriveInfo driveInfo = new DriveInfo("D"); Console.WriteLine(driveInfo.Name); Console.WriteLine(driveInfo.VolumeLabel); Console.WriteLine(driveInfo.AvailableFreeSpace); Console.WriteLine(driveInfo.TotalFreeSpace); Console.WriteLine(driveInfo.TotalSize); Console.WriteLine(driveInfo.DriveFormat); Console.WriteLine(driveInfo.DriveType); } }
輸出
以下是輸出 -
D: NTFS 76767677788 76767677788 45463434799 NTFS Fixed
註釋 - 輸出可能因作業系統而異。
廣告