Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: JosephGloszPosted on 2008-09-03 at 18:23:23ID: 22383589
well, for starters, you could use two native Delphi routines: DiskFree and DiskSize. You can look in help for their syntax, i.e.:
(drv), pVolName, MAX_PATH, nVNameSer,maxCmpLen, FSSysFlags, pFSBuf, MAX_PATH);
rv), AvailToCaller, TotalBytes, TotalFreeBytes);
on.ExeName ); (drv), pVolName, MAX_PATH, nVNameSer,
rv), AvailToCaller, TotalBytes, TotalFreeBytes);
function DiskSize(Drive: Byte): Int64;
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.
so something like this would work:
type
TDriveChars = 'A'..'Z';
var
Drive: char;
iDrive: Byte;
DiskInfo: array[TDriveChars] of Int64;
begin
for Drive := 'A' to 'Z' do
begin
iDrive := ord(Drive) - ord('A') + 1; //maps 'A' to 1, 'B' to 2 etc...
DiskInfo[Drive] := DiskSize(iDrive);
end;
So any array entry that isn't "-1" is a valid drive.
Then, once you have all the valid drives you can continue with
GetVolumeInformation(PChar
GetDiskFreeSpaceEx(PChar(d
our code makes those exact calls and it works beautifully.
Here is the complete code snippet (actually adapted from somewhere else). Some of the fields are TComputerInfo properties. Adapt this as you see fit....
procedure TComputerInfo.GetHDInfo;
var
drv : String;
pVolName : PChar;
nVNameSer : PDWORD;
maxCmpLen : DWord;
FSSysFlags : DWord;
pFSBuf : PChar;
AvailToCaller, TotalBytes: Int64;
TotalFreeBytes: PLargeInteger;
begin
GetMem(pVolName, MAX_PATH);
GetMem(pFSBuf, MAX_PATH);
GetMem(nVNameSer, MAX_PATH);
GetMem(TotalFreeBytes, MAX_PATH);
// Get OS information
bNT := GetNT;
sOS := GetWinVersion;
// Get drive letter
drv := ExtractFileDrive(Applicati
//Get the volume information
GetVolumeInformation(PChar
maxCmpLen, FSSysFlags, pFSBuf, MAX_PATH);
sLetter := drv;
// Get Free Space. GetDiskFreeSpaceEx works on 98 or greater.
if ((bNT = false) and (Version = '4.0')) then begin
raise Exception.Create('Hard drive capacity and free space can not be determined in Windows 95.');
iCapacity := 0;
iFreeSpace := 0;
end
else begin
GetDiskFreeSpaceEx(PChar(d
iCapacity := (TotalBytes div 1048576);
iFreeSpace := (TotalFreeBytes^ div 1048576);
end;