RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.DiskSize Function

Returns the size, in bytes, of a specified drive.

Pascal
function DiskSize(Drive: Byte): Int64;
C++
Int64 DiskSize(Byte Drive);

DiskSize returns the size in bytes of the specified drive, where 0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number is invalid.

Note: DiskSize is only available on Windows.
 

C++ Examples: 

 

/*
This example uses a form with a label on it. When the
following code executes, it displays a message in the label
indicating the number of KB free, and what percentage of the
entire disk space that represents.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  __int64 AmtFree = DiskFree(0);
  __int64 Total = DiskSize(0);
  AnsiString S;
  S.sprintf("%I64d percent of the space on drive 0 is free: %I64d KB", AmtFree*100/Total, AmtFree/1024 );
  Label1->Caption = S;
}

 

Delphi Examples: 

{
This example uses a form with a label on it. When the
following code executes, it displays a message in the label
indicating the number of KB free, and what percentage of the
entire disk space that represents.
} 
procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
  AmtFree: Int64;
  Total:   Int64;
begin
  AmtFree := SysUtils.DiskFree(0);
  Total := DiskSize(0);
  S := IntToStr((AmtFree  * 100) div Total) + ' percent of the space on drive 0 is free: ' + IntToStr(AmtFree div 1024) + ' Kbytes free. ';
  Label1.Caption := S;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!