: : : : : Well at this point I am stupified and don't know where to go from here. Output looks great until one gets into the high capacity drives.
: : : : : Exp. 999934 Kbytes total capacity on drive c: <-- I don't like Kbytes as an answer.
: : : :
: : : : If you look at the value of the various measurements you'll see a pattern:
: : : :
: : : : 1 kilobyte = 1024 bytes
: : : : 1 megabyte = 1024 kilobytes
: : : : 1 gigabyte = 1024 megabytes
: : : : 1 terrabyte = 1024 gigabytes
: : : :
: : : : So basically, whenever you want to move up to the next unit of measurement you divide by 1024. In this case, the number of kilobytes / 1024 will give you the number of megabytes.
: : : :
: : :
: : : Okay I get the basic idea but the math is what I am not able to solve. I have tried divide by all types of #'s and the answer I have gotten so far is 9.764e+2. This is nowhere correct due to the drive I am working with is software measured 4.87GB. A little more of a hint would be great but without totally giving away the farm if you know what I mean. Thanks again Solo5300
: : :
: : This is a limitation set by the size of the integer type. Because a longint is a signed 32 bit number, it means that the largest number you'll get is 2^31-1, which is about 2 GB. If the number is larger than that the variable will overflow and start at the lowest value (-2GB) and count upwards again. So a 4.87 GB drive will show as a about a 0.87 GB drive or about 900 MB.
: : Unfortunately there is no way of knowing how often a variable has overflown its maximum, thus a 900 MB drive could be 900 MB, 4.87 GB, 8.87 GB, etc. There is a very slow way to determine the size of any drive, as long as the free space is less than 2 GB: Add together the sizes of all the files and the free space.
: :
:
: Thats why what ever I seem to do is rejected and basicly gives the same answer or an extended view of the same answer. Great that brings me a step closer to trying to figure out what I am doing...
:
: Thanks Again
: Solo5300
Well, this isn't perfect either, but it will get you farther. This code will handle up to 2gig drives, part of the problem being that Pascal's largest variable, LongInt, will only go up to 2,147,483,647 (or 2.1 gig)
To go larger than this, you would have to create your own variable and I don't think this function will get higher values anyways, HOWEVER...
With this, if the drive size is > 2.1gig then it returns a size of 1 byte (since you will never find a 1 byte drive). If it returned 1, then you could implement zibadian's idea.
Anyways, here's the code:
{
BO BENDTSEN
Many people don't think about it, but DOS is limited to report more than
1 gigabyte. I have a 1.3 and a 1.0 gig, and made these routines for my
programs for knowing if the drive size is more than 1 gig. Using the normal
DiskSize and DiskFree could get you strange result, sometimes it could report
maybe 100MB when it is really 1 gig.
If the size of free space is 1 you can assume that the drive is more than 1
gigabyte.
}
USES Dos;
VAR
X : Byte;
Function DriveSize(d : byte) : Longint; { -1 not found, 1=>1 Giga }
Var
R : Registers;
Begin
With R Do
Begin
ah := $36;
dl := d;
Intr($21, R);
If AX = $FFFF Then
DriveSize := -1 { Drive not found }
Else
If (DX = $FFFF) or
(Longint(ax) * cx * dx = 1073725440) Then
DriveSize := 1
Else
DriveSize := Longint(ax) * cx * dx;
End;
End;
Function DriveFree(d : byte) : Longint; { -1 not found, 1=>1 Giga }
Var
R : Registers;
Begin
With R Do
}
USES Dos;
VAR
X : Byte;
Function DriveSize(d : byte) : Longint; { -1 not found, 1=>1 Giga }
Var
R : Registers;
Begin
With R Do
Begin
ah := $36;
dl := d;
Intr($21, R);
If AX = $FFFF Then
DriveSize := -1 { Drive not found }
Else
If (DX = $FFFF) or
(Longint(ax) * cx * dx = 1073725440) Then
DriveSize := 1
Else
DriveSize := Longint(ax) * cx * dx;
End;
End;
Function DriveFree(d : byte) : Longint; { -1 not found, 1=>1 Giga }
Var
R : Registers;
Begin
With R Do
Begin
ah := $36;
dl := d;
Intr($21, R);
If AX = $FFFF Then
DriveFree := -1 { Drive not found }
Else
If (BX = $FFFF) or (Longint(ax) * bx * cx = 1073725440) Then
DriveFree := 1
Else
DriveFree := Longint(ax) * bx * cx;
End;
End;
Begin
For X := 3 to 26 Do
If DriveSize(X) > 0 Then
Begin
WriteLn('Drive ',Chr(X+64),':');
WriteLn(' ',DriveSize(X),' bytes');
WriteLn(' ',DriveFree(X),' bytes');
End;
End.
Phat Nat