Verificar o espaco que tem em dico...

Delphi

16/08/2003

Como faco para verificar o espaco que tem em disco e o tamanho do HD...


Desde ja muito GRATO!


Programadorjlle

Programadorjlle

Curtidas 0

Respostas

Cebikyn

Cebikyn

16/08/2003

Use a função abaixo:

function GetDiskSize(drive: Char; var free_size, total_size: Int64): boolean;
var
  RootPath: array[0..4] of Char;
  RootPtr: PChar;
  current_dir: string;
begin
  RootPath[0] := Drive;
  RootPath[1] := ´:´;
  RootPath[2] := ´\´;
  RootPath[3] := 0;
  RootPtr := RootPath;
  current_dir := GetCurrentDir;
  if SetCurrentDir(drive + ´:\´) then
  begin
    GetDiskFreeSpaceEx(RootPtr, Free_size, Total_size, nil);
    // this to turn back to original dir
    SetCurrentDir(current_dir);
    Result := True;
  end
  else
  begin
    Result := False;
    Free_size  := -1;
    Total_size := -1;
  end;
end;


Para usar a função:

var
  espaco_livre, espaco_total: Int64;
begin
  if GetDiskSize(´C´, espaco_livre, espaco_total)
  then
    ShowMessage(´Espaço livre = ´ +
      IntToStr(espaco_livre) + #13 + ´Espaço total = ´ +
      IntToStr(espaco_total))
  else
    ShowMessage(´Drive não acessível´); 
end;



GOSTEI 0
POSTAR