GetDiskFreeSpace 回傳磁碟幾何組織參數:每簇扇區數、每扇區位元組數、空閒簇數、總簇數。雖受限於 32 位元 (最大 2TB),但可計算簇大小、扇區大小等底層資訊,適用於磁碟工具、檔案系統分析。
function GetDiskFreeSpace(
lpRootPathName: PChar;
var lpSectorsPerCluster: DWORD;
var lpBytesPerSector: DWORD;
var lpNumberOfFreeClusters: DWORD;
var lpTotalNumberOfClusters: DWORD
): BOOL; stdcall;
procedure TForm1.FormCreate(Sender: TObject);
var
d1, d2, d3, d4: DWORD;
begin
GetDiskFreeSpace('C:\', d1, d2, d3, d4);
Memo1.Clear;
with Memo1.Lines do
begin
Add(Format('每簇扇區數: %d', [d1]));
Add(Format('每扇區位元組數: %d', [d2]));
Add(Format('空閒簇數: %d', [d3]));
Add(Format('總簇數: %d', [d4]));
Add(Format('剩餘空間: %.2f GB', [d3 / 1024 / 1024 / 1024 * d2 * d1]));
Add(Format('總空間: %.2f GB', [d4 / 1024 / 1024 / 1024 * d2 * d1]));
end;
end;

SectorsPerCluster * BytesPerSectorTotalClusters * ClusterSizeFreeClusters * ClusterSize常見值:NTFS 預設簇 4KB (8 扇區 × 512 位元組);FAT32 視分區大小而定 (4KB~32KB)。