I'm using a c# program to see how many GB are still free on a hard drive (total size 1 TB, free size 110 GB (to be exact, according to drive properties in Windows explorer: 118.333.329.408 Bytes) according to Windows).
My problem is that the result I'm getting is.....off.
It's 10,135,252,992 Bytes according to the C# method I'm using below.....but according to Windows 110! GB are free.
Note: I'm talking about a Windows Server
here and the drive is the D drive. So no swap file on it, and no hidden System files (at least not more than any non System drive has as the System drive is the C drive).
public long GetTotalFreeSpace(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalFreeSpace;
}
}
return -1;
}
My question here is how can that be and how to correct it?
If the (external) hard drive shows less space than it should because of MBR style, you can fix this problem by converting MBR to GPT and then extend the partition though adding the unallocated space. The following video shows you to convert MBR to GPT with Windows Disk Management and EaseUS Partition Master.
Your drive shows up smaller than advertised because storage drive capacity is calculated and reported slightly differently than other capacities in computing.
In Windows 7/Vista/XP, Hard Disk Drives and Devices with Removable Storage are listed separately. In newer versions of Windows, you can see right under the drive listing how much free space is left on it, as well as the total size of the drive, in a format like this:
Right-click Windows Start Menu and select Disk Management to open it. Step 2. In the main interface of Disk management, select a target hard drive that shows the wrong free space and right-clicks it to choose Properties. Step 3. In the new window, scroll down to Tools tab and click on Check to continue.
Disktective is another free disk space analyzer for Windows. This one is completely portable and takes up less than 1 MB of disk space, so you can easily carry it with you on a flash drive. Each time Disktective opens, it immediately asks what directory you want to scan.
It suggested that if there is not any failure on the disk, then it should be the system backup made by Windows/other software. Later on, I use TreeSize and successfully identify the folder of that unknown space.
Under the hood, the System.IO.DriveInfo assembly appears to use the GetDiskFreeSpaceEx function from the Windows API.
The difference between the standard version of GetDiskFreeSpace
and GetDiskFreeSpaceEx
comes down to this:
GetDiskFreeSpace:
GetDiskFreeSpace function Retrieves information about the specified disk, including the amount of free space on the disk.
GetDiskFreeSpaceEx:
GetDiskFreeSpaceEx function Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.
Most likely, you're hitting some quota on the space available to the current user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With