RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.DiskFree Function

Returns the number of free bytes on a specified drive.

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

DiskFree returns the number of free bytes on the specified drive, where 0 = Current, 1 = A, 2 = B, and so on. 

DiskFree returns -1 if the drive number is invalid.

Note: DiskFree 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;
}
/*
The following example displays in a dialog the disk free
space of the current drive with commas as thousand separators.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  ShowMessage(FormatFloat("#,##0 bytes", DiskFree(0)));
}

 

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;
{
The following example displays in a dialog the disk free 
space of the current drive with commas as thousand separators.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(FormatFloat('#,##0 bytes', DiskFree(0)));
end;

 

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