如何使用 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

註釋 - 輸出可能因作業系統而異。

更新日期:2020 年 4 月 8 日

189 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告