Как определить свободное дисковое пространство на дисках в Delphi?

function GetDiskFreeSpaceEx(lpDirectoryName: PAnsiChar; var lpFreeBytesAvailableToCaller: Integer; 
                            var lpTotalNumberOfBytes: Integer; var lpTotalNumberOfFreeBytes: Integer): bool; 
stdcall; 
external kernel32 name 'GetDiskFreeSpaceExA'; 
  
procedure GetDiskSizeAvail(TheDrive : PChar; var TotalBytes : double; var TotalFree : double); 
var
  AvailToCall : integer; 
  TheSize : integer; 
  FreeAvail : integer; 
begin
  GetDiskFreeSpaceEx(TheDrive, AvailToCall, TheSize, FreeAvail); 
  {$IFOPT Q+}
  {$DEFINE TURNOVERFLOWON}
  {$Q-} 
  {$ENDIF} 
  if TheSize >= 0 then
    TotalBytes := TheSize else
  if TheSize = -1 then
  begin
    TotalBytes := $7FFFFFFF; 
    TotalBytes := TotalBytes * 2; 
    TotalBytes := TotalBytes + 1; 
  end else
  begin
    TotalBytes := $7FFFFFFF; 
    TotalBytes := TotalBytes + abs($7FFFFFFF - TheSize); 
  end; 
  
  if AvailToCall >= 0 then
    TotalFree := AvailToCall else
  if AvailToCall = -1 then
  begin
    TotalFree := $7FFFFFFF; 
    TotalFree := TotalFree * 2; 
    TotalFree := TotalFree + 1; 
  end else
  begin
    TotalFree := $7FFFFFFF; 
    TotalFree := TotalFree + abs($7FFFFFFF - AvailToCall); 
  end; 
end; 
  
procedure TForm1.Button1Click(Sender: TObject); 
var
  TotalBytes : double; 
  TotalFree : double; 
begin
  GetDiskSizeAvail('C:\', TotalBytes, TotalFree); 
  ShowMessage(FloatToStr(TotalBytes)); 
  ShowMessage(FloatToStr(TotalFree)); 
end; 

1 Звезда2 Звезды3 Звезды4 Звезды5 Звезд (10 оценок, среднее: 5,00 из 5)
Загрузка...
Добавить комментарий