標籤:style blog http java color get
原文:C# 擷取磁碟容量
/// 擷取指定磁碟機的空間總大小(單位為B) /// </summary> /// <param name="str_HardDiskName">只需輸入代表磁碟機的字母即可 </param> /// <returns> </returns> public static long GetHardDiskSpace(string str_HardDiskName) { long totalSize= new long(); str_HardDiskName=str_HardDiskName +":\\"; System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo drive in drives) { if (drive.Name == str_HardDiskName) { totalSize = drive.TotalSize; } } return totalSize; } /// <summary> /// 擷取指定磁碟機的剩餘空間總大小(單位為B) /// </summary> /// <param name="str_HardDiskName">只需輸入代表磁碟機的字母即可 </param> /// <returns> </returns> public static long GetHardDiskFreeSpace(string str_HardDiskName) { long freeSpace = new long(); str_HardDiskName = str_HardDiskName + ":\\"; System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo drive in drives) { if (drive.Name == str_HardDiskName) { freeSpace = drive.TotalFreeSpace; } }
其它相關:
轉自:http://www.cnblogs.com/jyshi/