我想使用C#訪問計算機上邏輯驅動器的信息。我應該如何做到這一點?謝謝!如何在C#中檢索磁盤信息?
41
A
回答
67
對於大多數信息,您可以使用DriveInfo類。
using System;
using System.IO;
class Info {
public static void Main() {
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives) {
//There are more attributes you can use.
//Check the MSDN link for a complete example.
Console.WriteLine(drive.Name);
if (drive.IsReady) Console.WriteLine(drive.TotalSize);
}
}
}
2
檢查DriveInfo類,看它是否包含您需要的所有信息。
4
使用System.IO.DriveInfo類 http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
5
怎麼樣安裝卷,那就是你有沒有盤符?
foreach(ManagementObject volume in
new ManagementObjectSearcher("Select * from Win32_Volume").Get())
{
if(volume["FreeSpace"] != null)
{
Console.WriteLine("{0} = {1} out of {2}",
volume["Name"],
ulong.Parse(volume["FreeSpace"].ToString()).ToString("#,##0"),
ulong.Parse(volume["Capacity"].ToString()).ToString("#,##0"));
}
}
3
如果你想在本地計算機,以獲取信息爲單/特定的驅動器。你可以使用DriveInfo類別:
//C Drive Path, this is useful when you are about to find a Drive root from a Location Path.
string path = "C:\\Windows";
//Find its root directory i.e "C:\\"
string rootDir = Directory.GetDirectoryRoot(path);
//Get all information of Drive i.e C
DriveInfo driveInfo = new DriveInfo(rootDir); //you can pass Drive path here e.g DriveInfo("C:\\")
long availableFreeSpace = driveInfo.AvailableFreeSpace;
string driveFormat = driveInfo.DriveFormat;
string name = driveInfo.Name;
long totalSize = driveInfo.TotalSize;
相關問題
- 1. 從遠程服務器C檢索磁盤信息#
- 2. 如何檢索有關磁盤卷的信息?
- 3. 如何獲取磁盤性能信息?
- 4. 如何檢查EBS卷的磁盤信息
- 5. 獲取磁盤幾何信息
- 6. C#我如何檢索這些信息?
- 7. 在fwrite中檢測磁盤刪除C
- 8. 檢索信息
- 9. 如何從數組中檢索信息
- 10. 如何從jTextField中檢索信息
- 11. 如何從url中檢索信息?
- 12. 如何從$ .post中檢索信息
- 13. 如何在磁盤
- 14. 用c#查看磁盤管理信息 - 含。隱藏卷
- 15. 如何添加磁盤信息Inno Setup的
- 16. 如何獲取磁盤製造商信息?
- 17. 如何堅持MEF導入和導出信息到磁盤
- 18. 如何獲取有關磁盤文件系統的信息?
- 19. 如何使用Lotus腳本獲取系統/磁盤信息?
- 20. 保存Drawable到磁盤並檢索 - Android
- 21. 如何檢索c#中.Net dll的證書信息
- 22. 如何從C#中像天氣檢索信息#
- 23. 從表中檢索信息
- 24. 從url中檢索信息
- 25. 從OLAP中檢索信息
- 26. 檢索DLL信息
- 27. ADHoc信息檢索
- 28. 檢查磁盤Powershell
- 29. 使用C#檢索表模式信息
- 30. 檢索訪問信息Google gdata-api C#
不錯,謝謝! – leo 2009-01-05 09:37:14
除了本地計算機以外的其他計算機上的驅動器信息如何? – flipdoubt 2009-01-05 12:13:40