Test code:
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. IO;
Namespace driveinfohelper
{
Class Program
{
Static void main (string [] ARGs)
{
Driveinfo [] drives = driveinfo. getdrives ();
Console. writeline ("drive name/T type/T format/T total space/T available space ");
Foreach (driveinfo di in drives)
{
Console. writeline (string. format ("{0}/T {1}/t {2}/t {3}/t {4}", Di. name, Di. drivetype, Di. driveformat, Di. totalsize, Di. totalfreespace ));
}
}
}
}
Error message:
Drive name Type format total space available
C:/fixed NTFS 132409556992 103559319552
D:/fixed NTFS 20970467328 875720704
Unprocessed exception: system. Io. ioexception: the device is not ready.
In system. Io. _ error. winioerror (int32 errorcode, string maybefullpath)
In system. Io. _ error. winiodriveerror (string drivename, int32 errorcode)
In system. Io. driveinfo. get_driveformat ()
In driveinfohelper. program. Main (string [] ARGs) Location D:/exercises/driveinfoel
PER/driveinfohelper/program. CS: row number 16
Press any key to continue...
When the optical drive is attached to a CD, the following message is displayed:
Drive name Type format total space available
C:/fixed NTFS 132409556992 103559266304
D:/fixed NTFS 20970467328 875720704
E:/CDROM, CDFs 719345664, 0
Press any key to continue...
Note: It turns out that the optical drive is not equipped with a CD! Haha