
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Querying Information for All Drives on a System
|
747
Notice that only the drive letter is passed in to the Driveinfo constructor. This drive
letter can be either uppercase or lowercase—it does not matter. The next thing you
will notice with the code in Example 12-15 and the code in the Solution to this rec-
ipe is that the
IsReady property is always tested for true before either using the drive
or querying its properties. If we did not test this property for
true and for some rea-
son the drive was not ready (e.g., a CD was not in the drive at that time), a
System.
IO.IOException
would be returned stating that “The device is not ready.” To prevent
this exception from being thrown (since it is an expensive operation), simply test the
IsReady property to determine if it is true or not.
For the Solution to this recipe, the
DriveInfo constructor was not used. Instead, the
static
GetDrives method of the DriveInfo class was used to return an array of
DriveInfo objects. Each DriveInfo object in this array corresponds to one drive on
the current system.
The
DriveType property of the DriveInfo class returns an enumeration value from the
DriveType enumeration (yes, they have the same name, unfortunately). This enumer-
ation value identifies what type of drive the current
DriveInfo object represents.
Table ...