Meshbeyn / Projects

namespace NTFSExtensions

public class DiskFreeSpace

This class calls during construction the WinAPI function GetDiskFreeSpace and saves the results in corresponding fields.


public DiskFreeSpace(String RootPathName)
Call GetDiskFreeSpace with RootPathName as path parameter.


public int BytesPerCluster
Calculated size of a volume cluster in bytes.
public int BytesPerSector
Drive sector size. This depends on drive. Most used values are 512 or 4096.
public long NumberOfFreeBytes
Calculated amount of free bytes on volume.
public int NumberOfFreeClusters
Number of free clusters on volume.
public int SectorsPerCluster
How many sectors contains a cluster. This depends on NTFS formating options and drive sector size. Most used values are 8 or 1.
public long TotalBytes
Calculated size of volume in bytes.
public int TotalNumberOfClusters
Size of volume in clusters.
public String UsedRoot
The path used to create this object.


You may create this object using any folder path on interesting volume if you have access rights to list this folder. To inspect current volume, create new object with null as RootPathName value.


public static void TestGetDiskFreeSpace()
    DiskFreeSpace DFS = new DiskFreeSpace("c:\\Program Files");
    Console.WriteLine("Volume information for volume C: using directory {0}", DFS.UsedRoot);
    Console.WriteLine("Sector size:\t{0}", DFS.BytesPerSector);
    Console.WriteLine("Cluster size:\t{0}", DFS.BytesPerCluster);
    Console.WriteLine("Free clusters:\t{0:N0}, in bytes: {1:N0}", DFS.NumberOfFreeClusters, DFS.NumberOfFreeBytes);
    Console.WriteLine("Total clusters:\t{0:N0}, in bytes: {1:N0}", DFS.TotalNumberOfClusters, DFS.TotalBytes);
Volume information for volume C: using directory c:\Program Files
Sector size:    512
Cluster size:   4096
Free clusters:  49.195.861, in bytes: 201.506.246.656
Total clusters: 62.514.175, in bytes:
Output of code example