I used the following method to calculate free disk space using DriveInfo class. But it doesn't match the free disk space value shown in My Computer. Following method returns 106 gb of free space while MyComputer only shows a free space of 98.8 GB. How can I calculate the accurate value? Why is there a difference?
public long GetTotalFreeSpace(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalFreeSpace;
}
}
return -1;
}