public static long GetHardDiskSpace(string str_HardDiskName) { long totalSize = 0; str_HardDiskName = str_HardDiskName + ":\"; DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo drive in drives) { if (drive.Name == str_HardDiskName) { totalSize = drive.TotalFreeSpace *100/ drive.TotalSize; } } return totalSize; }
使用方法: 传如参数C 、D、 E、 F等盘符的名字。