DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo info in drives)
{
Console.WriteLine("Name: {0} (RootDirectory: {1}",
info.Name, info.RootDirectory);
Console.WriteLine("DriveType: {0}", info.DriveType);
Console.WriteLine("IsReady: {0}", info.IsReady);
//you'll get an exception if you try to read some
//info when the drive isn't ready
if (info.IsReady)
{
Console.WriteLine("VolumeLabel: {0}", info.VolumeLabel);
Console.WriteLine("DriveFormat: {0}", info.DriveFormat);
Console.WriteLine("TotalSize: {0:N0}", info.TotalSize);
Console.WriteLine("TotalFreeSpace: {0:N0}", info.TotalFreeSpace);
Console.WriteLine("AvailableFreeSpace: {0:N0}",
info.AvailableFreeSpace);
}
Console.WriteLine();
}
Name: A:\ (RootDirectory: A:\)
DriveType: Removable
IsReady: False
Name: C:\ (RootDirectory: C:\)
DriveType: Fixed
IsReady: True
VolumeLabel:
DriveFormat: NTFS
TotalSize: 160,045,199,360
TotalFreeSpace: 81,141,878,784
AvailableFreeSpace: 81,141,878,784
Name: F:\ (RootDirectory: F:\)
DriveType: CDRom
IsReady: False
Name: H:\ (RootDirectory: H:\)
DriveType: Removable
IsReady: False