Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 Checking available disk space on large drives.


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

    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 = -  then begin
        TotalBytes := $7FFFFFFF;
        TotalBytes := TotalBytes * 2;
        TotalBytes := TotalBytes +  ;
      end else
      begin
        TotalBytes := $7FFFFFFF;
        TotalBytes := TotalBytes + abs($7FFFFFFF - TheSize);
      end;

    if AvailToCall >= 0 then TotalFree := AvailToCall else if AvailToCall = - then begin TotalFree := $7FFFFFFF; TotalFree := TotalFree * 2; TotalFree := TotalFree + ; end else begin TotalFree := $7FFFFFFF; TotalFree := TotalFree + abs($7FFFFFFF - AvailToCall); end; end; procedure TForm .Button Click(Sender: TObject); var TotalBytes : double; TotalFree : double; begin GetDiskSizeAvail('C:\', TotalBytes, TotalFree); ShowMessage(FloatToStr(TotalBytes)); ShowMessage(FloatToStr(TotalFree)); end;

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use