Title: Getting the Free Disk Space and Capacity
Question: How can i get the free disk space and capacity?
Answer:
We use DiskSize and DiskFree functions in this solution.DiskFree returns the number of free bytes on the specified drive number, where 0 = Current, 1 = A,
2 = B, 3 = C, and so on.DiskFree returns -1 if the drive number is invalid.
In the same way, DiskSize returns the size in bytes of the specified drive number, where 0 = Current, 1 = A, 2 = B, 3 = C, and so on. DiskSize returns -1 if the drive number is invalid.
You can try this solution placing a TMemo and a Tbutton on a form and adding this code to the OnClick event of the button.
The resulting values are in byte but I convert it as megabyte.I hope it will help you.I am sure that many others made a better solution than mine.
Sample call:
procedure TForm1.Button1Click(Sender: TObject);
var
s:Integer;
begin
List.Clear;
for s:=1 to 30 do
if DiskFree(s)-1 then
begin
List.Lines.Add(chr(s+64)+': ');
List.Text:=List.Text+FloatToStrF(DiskSize(s)/
1048576,ffFixed,10,2)+' MB Capacity';
List.Text:=List.Text+'....';
List.Text:=List.Text+FloatToStrF(DiskFree(s)/
1048576,ffFixed,10,2)+' MB Free Space';
end;
end;