Solved

Get Capacity of whole HDD

Posted on 2001-08-30
5
182 Views
Last Modified: 2012-05-04
hi ! how can i get the capacity of my whole fixed drives ?

kind regards
ItsMe

(must be work under nt/95/98/2000)
0
Comment
Question by:ItsMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Expert Comment

by:aubs
ID: 6444025
Hi ItsMe,

you could try something like:

procedure TForm1.Button1Click(Sender: TObject);
var
  FreeAvailable, TotalSpace: Int64;
  TotalFree: PLargeInteger;
begin
  if GetDiskFreeSpaceEx('C:',FreeAvailable,TotalSpace,TotalFree) then
    label1.caption:= inttostr(TotalSpace);
end;

There is GetDiskFreeSpace function aswell, but it does not report on drives larger than 2GB. From the online help:

[New - Windows NT]

[New - Windows 95, OEM Service Release 2]

The GetDiskFreeSpaceEx function obtains information about the amount of space available on a disk volume: the total amount of space, the total amount of free space, and the total amount of free space available to the user associated with the calling thread.
Windows 95 OSR 2:

The GetDiskFreeSpaceEx function is available on Windows 95 systems beginning with OEM Service Release 2 (OSR 2).
Use the GetVersionEx function to determine that a system is running OSR 2 or a later release of the Windows 95 operating system. The GetVersionEx function fills in the members of an OSVERSIONINFO data structure. If the dwPlatformId member of that structure is VER_PLATFORM_WIN32_WINDOWS, and the low word of the dwBuildNumber member is greater than 1000, the system is running OSR 2 or a later release.

Once you have determined that a system is running OSR 2, call the LoadLibrary or LoadLibraryEx function to load the KERNEL32.DLL file, then call the GetProcAddress function to obtain an address for the GetDiskFreeSpaceEx function. Use that address to call the function.

regards

Aubs
0
 
LVL 2

Expert Comment

by:aubs
ID: 6444060
or a more complete solution:

procedure TForm1.Button1Click(Sender: TObject);
var
  Directory: PChar;
  FreeAvailable, TotalSpace: Int64;
  TotalFree: PLargeInteger;
  msg: string;
begin
  Directory:='C:';
  if GetDiskFreeSpaceEx(Directory,FreeAvailable,TotalSpace,TotalFree) then
    begin
      msg:= 'Drive ' + Directory;
      msg:= msg + 'Total Capacity: ' + inttostr(TotalSpace) + ' bytes'#13#10;
      msg:= msg + 'Used Capacity: ' + inttostr(TotalSpace - FreeAvailable) + ' bytes'#13#10;
      msg:= msg + 'Free Capacity: ' + inttostr(FreeAvailable) + ' bytes'#13#10;
      ShowMessage(msg);
    end;
end;
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 30 total points
ID: 6444167

  ShowMessage(IntToStr(DiskSize(0)));


 DiskSize returns the size in bytes of the specified drive, where 0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number is invalid.
 
 

0
 
LVL 1

Expert Comment

by:Phoenix_s
ID: 6446545
mnasman's answer works under win2k pro, and win98 SE

the only tricky part is to make dure the drive # is correct
0
 

Author Comment

by:ItsMe
ID: 6446562
works fine,
thanks everybody ;-)

ItsMe
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi parse string to params 3 156
SUM 2 INTEGER ARRAYS INTO 1 10 111
Unique identifier on a terminal server (rdp) 4 74
how to change, disabled button color FMX ? 1 50
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question