我有这个程序,但是当它尝试访问 FIRST 时出现问题... 我需要分离驱动程序并且只获得 C:\ 的总大小。当程序在 if... 处停止时,表示驱动器尚未准备好。我能做些什么?
class Program
{
static void Main(string[] args)
{
string mainHD = Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
GetTotalFreeSpace(mainHD);
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if (drive.VolumeLabel != @"C:\")
{
//There are more attributes you can use.
//Check the MSDN link for a complete example.
string drivesname = drive.Name;
Console.WriteLine(drivesname);
if (drive.IsReady) Console.WriteLine(drive.TotalSize);
}
}
Console.ReadLine();
}
private static long GetTotalFreeSpace(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalSize;
}
}
return -1;
}
}
}