2006. július 25., kedd

Get disk free space


Problem/Question/Abstract:

How can i get disk free space?

Answer:

function GetDiskFree(Drive: char): int64;
{ func to return the free space of a drive in bytes. }
var
{$IFDEF Delphi3Below}
  lpFreeBytesAvailableToCaller,
    lpTotalNumberOfBytes,
    lpTotalNumberOfFreeBytes: comp;
{$ELSE}
  lpFreeBytesAvailableToCaller,
    lpTotalNumberOfBytes,
    lpTotalNumberOfFreeBytes: TLargeInteger;
{$ENDIF}
begin
  if GetDiskFreeSpaceEx(PChar(Drive + ':\'), lpFreeBytesAvailableToCaller,
    lpTotalNumberOfBytes, @lpTotalNumberOfFreeBytes) then
    Result := lpTotalNumberOfFreeBytes
  else
    Result := -1;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  ShowMessage('a:' + IntToStr(GetDiskFree('a')));
  ShowMessage('c:' + IntToStr(GetDiskFree('c')));
end;

Nincsenek megjegyzések:

Megjegyzés küldése