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;//剩余容量 freeSpace = drive.TotalSize; //总容量 } } return freeSpace; }