Checking available disk space on large drives

2GB, CheckDiskSpace, Large Disk

Question and Answer Database

FAQ2552D.txt Checking available disk space on large drives.
Category :Windows API
Platform :All
Product :All 32 bit

Question:
How do I check for available diskspace on a drive larger than 2
gigabytes?

Answer:
You will need to call the Windows API function GetDiskFreeSpaceEx()
and convert the returned integers to doubles, since integers greater
than 2 gigabytes are not supported in Delphi.

Example:

[code lang=“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;
[/code]

7/16/98 4:31:28 PM

Trademarks & Copyright © 1998 INPRISE Corporation. Last modified on
8-December-1998.

[tags]Delphi, System[/tags]

0 Kommentare zu “Checking available disk space on large drives

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.