Get total size for a Drive in CSharp
Description
The following code shows how to get total size for a Drive.
Example
using System;//from w w w. ja v a2s. c o m
using System.IO;
class Test
{
public static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(" Total available space: {0, 15} bytes",d.TotalFreeSpace);
Console.WriteLine(" Total size of drive: {0, 15} bytes ",d.TotalSize);
}
}
}
}
The code above generates the following result.