Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

GetDiskFreeSpaceEx

Is available any demo app that can show disk free space ?

 with theese function or other ?

 Esk
0
esk
Asked:
esk
  • 8
  • 6
  • 3
1 Solution
 
EpsylonCommented:
Use the DiskFree function:

function DiskFree(Drive: Byte): Int64;

0 = current drive
1 = A:
2 = B:
3 = C:
etc...
0
 
intheCommented:
The functions DiskSize & DiskFree are not capable of handling drives larger than 2 gigabyte..

THIS IS FROM SOME FAQ:
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:

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;


Regards Barry
0
 
EpsylonCommented:
>The functions DiskSize & DiskFree are not capable of handling drives larger than 2 gigabyte..

In Delphi 4 and 5 they work perfectly!
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
intheCommented:
mmm..i had to search to some searching cause i was sure i was right about the drive limits.and yes your correct for d4/5 , for other versions of delphi it returns longint so that is why the drive size limit of less than 2gig. ;-)
0
 
eskAuthor Commented:
Inthe, i get an error in this line

 GetDiskFreeSpaceEx(TheDrive,
                                           AvailToCall,
                                           TheSize,
                                           FreeAvail);
Not integer!

Esk
0
 
eskAuthor Commented:
Epsylon, this function does not return same size as Windows

function DiskFree(Drive: Byte): Int64;

Esk
0
 
intheCommented:
what version of delphi you using ?
0
 
eskAuthor Commented:
Here is a component that can shows free diskspace but it's .dcu file

http://www.besse.de/delphi/d40flib.htm
0
 
eskAuthor Commented:
Delphi 5. professional
0
 
EpsylonCommented:
Esk, DiskFree uses GetDiskFreeSpace internally. That means that GetDiskFreeSpace and GetDiskFreeSpaceEx will return the same values as DiskFree.
0
 
EpsylonCommented:
I have a 27 GB HDD here and DiskFree returns exactly the same as Windows tells me....
0
 
eskAuthor Commented:
I do this

Button1.Caption := IntToStr(DiskSize(3) Div 1024 Div 1024);
0
 
EpsylonCommented:
DiskSize? I though you needed DiskFree..?

Anyway, both function work ok here.
0
 
eskAuthor Commented:
This works

Esk
0
 
EpsylonCommented:
Alright, I can go to bed now   :o)
0
 
eskAuthor Commented:
i have one more.

how can i detect if no disk is in drive a:\

Esk
0
 
eskAuthor Commented:
it's okay, i have solve the problem. Found code.

Esk
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 8
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now