List the Drives on your Computer using C#

Feb 9, 2010 Posted by Lara Kannan
List the Drives on your Computer using C#?

Imagine you have two List. If you want to create a program to provide information about your Computer Drive, then use the System.IO.DriveInfo class.

The DriveInfo class can be used to determine the drives available on your computer, drive capacity, free space, type of drives etc. as shown below:


// Add namespace System.IO;

DriveInfo[] myDrives = DriveInfo.GetDrives();

foreach (DriveInfo di in myDrives)
{
Console.WriteLine(di.Name);
if (di.IsReady)
{
Console.WriteLine(di.TotalSize);
Console.WriteLine(di.DriveFormat);

Console.WriteLine(di.AvailableFreeSpace);
Console.WriteLine(di.TotalFreeSpace);

Console.WriteLine(di.DriveType);
Console.WriteLine(di.VolumeLabel);
}
}


Share
Labels: ,

Post a Comment