Function prototype:
BOOL GetDiskFreeSpace(
LPCTSTR lpRootPathName,
LPDWORD lpSectorsPerCluster,
LPDWORD lpBytesPerSector,
LPDWORD lpNumberOfFreeClusters,
LPDWORD lpTotalNumberOfClusters
);
Parameter description:
1.lpRootPathName: Specifies the name of the root directory of the test drive. When null, it is the root directory name of the drive where the current directory is located.
2.LpSectorsPerCluster: Get the number of sectors per cluster of the drive.
3.LpBytesPerSector: Get the number of bytes per sector of the drive.
4.LpNumberOfFreeClusters: The number of clusters remaining in disk space.
5.LpTotalNumberOfClusters: The number of clusters in the total disk space.
Application example:
Displays the total capacity of disk space and the remaining capacity.
1) Based on the above example, add two edit components and two label components, such as
2) Add the following content to the corresponding part of the onchange event of the combobox component:
val
disktotal,diskfree,cl1,cl2,sec1,byt1:longword;
Begin
Getdiskfreespace(pchar(combobox1.Items[combobox1.Items[combobox1.Items]),sec1,byt1,cl1,cl2);//Get disk information
Diskfree:=cl1*sec1*byt1;//Remaining capacity=number of remaining clusters*number of sectors per cluster*number of bytes per sector
disktotal:=cl2*sec1*byt1;//Total capacity=Total number of disk clusters*Number of sectors per cluster*Number of bytes per sector
edit2.text:=formatfloat(''##,##0'',total);
edit3.text:=formatfloat(''###,##0'',freesp);
end;