Board index » delphi » DiskFree for drives > 4GB, How ?

DiskFree for drives > 4GB, How ?

The DiskFree function returns a Longint, so how can I get the amount of
free space
for a drive > 4 GB ?.

--
Rob Lans
E-mail: rob.l...@nob.nl

 

Re:DiskFree for drives > 4GB, How ?


Quote
"Rob Lans" <rob.l...@nob.nl> wrote:
>The DiskFree function returns a Longint, so how can I get the amount of
>free space
>for a drive > 4 GB ?.

try this code...It uses the comp type 2^64 so it should report
accurately up to 64 tera-bytes, I think.

function TSystemInfo.GetAvailDriveSpace(const driveStr : pchar) :
comp;
var
   prevErrMode : UINT;
   driveStr : array[0..10] of char;
   drivePtr : PChar;
   SectPerClust, BytesPerSect, NumFreeClust, NumTotClust : DWORD;

begin
   // Function call for space.

   // Now, the exception should handle the information properly
   prevErrMode := SetErrorMode(SEM_FAILCRITICALERRORS);
   if GetDiskFreeSpace(
        drivePtr, SectPerClust, BytesPerSect,
         NumFreeClust, NumTotClust) then begin
      // Now, calculate the free space as a comp.
      result := SectPerClust;
      result := result * BytesPerSect * NumFreeClust;
   end else begin
      result := 0;
   end;
   SetErrorMode(prevErrMode);
end;

Jay Cole

Other Threads