Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - How to get total disk space of Windows drive?

I need to get total disk space in Delphi program.

like image 219
Little Helper Avatar asked Dec 07 '22 21:12

Little Helper


1 Answers

Use DiskSize and DiskFree functions for this problem. ComboBox1 contains a list of drives letters.

var
  Disk: Integer;
...
procedure TForm1.Button1Click(Sender: TObject);
var
  Total, Free: LongInt;
begin
  Total:=DiskSize(Disk) div 1024;
  Free:=DiskFree(Disk) div 1024;
  Gauge1.MaxValue:=Total;
  Gauge1.Progress:=Free;
  Label1.Caption:='Total size - '+IntToStr(Total);
  Label2.Caption:='Free - '+IntToStr(Free);
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  Disk:=ComboBox1.ItemIndex+1;
end;
like image 163
evilone Avatar answered Dec 31 '22 03:12

evilone