In this post, I will explain how to get the hard dive information of your system using C#.
TO get the hard drive information first we need to add the following namespace.
Now write the following method to get the information of all the drives of your system.
I hope this will be helpful for you. I would like to have any feedback from you. Your valuable feedback, question, or comments about this article are always welcome.
TO get the hard drive information first we need to add the following namespace.
using System.IO;
Now write the following method to get the information of all the drives of your system.
/// <summary>
/// Method to get the information of all the hard drives
/// </summary>
public static void GetDriveInformation()
{
try
{
//Get all the drives of system
DriveInfo[] drives = DriveInfo.GetDrives();
int count=0;
foreach (DriveInfo info in drives)
{
if (info.IsReady)
{
count += 1;
Console.WriteLine("*************Drive {0}*************", count);
Console.WriteLine("Drive Name:{0}", info.Name);
Console.WriteLine("Drive Size:{0} bytes", info.TotalSize.ToString());
Console.WriteLine("Free Space:{0} bytes", info.TotalFreeSpace.ToString());
Console.WriteLine("Drive Format:{0}", info.DriveFormat);
Console.WriteLine("Drive Type:{0}", info.DriveType);
Console.WriteLine("Drive Volume Label:{0}", info.VolumeLabel);
}
}
Console.ReadKey();
}
catch (Exception ex)
{
}
}
I hope this will be helpful for you. I would like to have any feedback from you. Your valuable feedback, question, or comments about this article are always welcome.
No comments:
Post a Comment