Listing Drives

Querying the computer’s drive letters and related information is achieved through the use of the DriveInfo class. To create instances of this type, either use the constructor that takes a drive letter (such as A, B:, or C:\), or use the GetDrives static method to get an array of all the drives on the machine.

Each DriveInfo object provides access to information about the drive represented by the object. This includes things such as the drive type (fixed disk, DVD, and so on), volume labels, free space, and so forth. The following example shows some of this information for all the drives on the machine:

static void Main(){    foreach (var drive in DriveInfo.GetDrives())    {        Console.WriteLine("{0} ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.