It looks like you're new here. If you want to get involved, click one of these buttons!

- 140.7K All Categories
- 103.5K Programming Languages
- 6.4K Assembler Developer
- 1.9K Basic
- 39.9K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 536 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 315 Console programming
- 90 DirectX Game dev
- 1 Minecraft
- 110 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 736 Computer Hardware
- 3.5K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 257 XML Development
- 3.3K Classifieds
- 198 Co-operative Projects
- 194 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 602 Jobs Wanted
- 206 Wanted
- 2.9K Microsoft .NET
- 1.7K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 7 Join the Team
- 77 User Profiles
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 620 Off topic board
- 186 Mobile & Wireless
- 60 Android
- 124 Palm Pilot
- 337 Multimedia
- 153 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 23 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- 0 Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 929 Software Development
- 416 Algorithms
- 68 Object Orientation
- 89 Project Management
- 93 Quality & Testing
- 262 Security
- 7.6K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 2 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 35 JQuery
- 297 WEB Servers
- 142 WEB-Services / SOAP

{ Date: 04/01/03 }

{ Description: Gives total Drive Capacity & Total Free capacity on a list of drives. }

{ For Windows: }

{ uses WinDos, WinCrt; }

uses Dos, crt;

begin

clrscr;

{Basic calculation for conversion reasons.}

Writeln('1 Kilobyte KB = 0.000977 Megabyte MB');

Writeln('Drive A & B are not counted as a drive due to being removable.');

Writeln('For use with system above Pentium 1 class Processors due to the');

Writeln('software limitations.');

Writeln('');

{Drive C:}

Writeln(DiskSize(3) div 1024, ' Kbytes total capacity on drive c:');

Writeln(DiskFree(3) div 1024, ' Kbytes free capacity on drive c:');

Writeln(' ');

{Drive }

Writeln(DiskSize(4) div 1024, ' Kbytes total capacity on drive d:');

Writeln(DiskFree(4) div 1024, ' Kbytes free capacity on drive d:');

Writeln(' ');

{Drive E:}

Writeln(DiskSize(5) div 1024, ' Kbytes total capacity on drive e:');

Writeln(DiskFree(5) div 1024, ' Kbytes free capacity on drive e:');

Writeln(' ');

end.

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.

I know that this has been drawn out and a long Question But any Ideas would be great. I know someone out there has done this before but I am just starting out this way.

Thanks,

Solo5300

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2015 Programmersheaven.com - All rights reserved.

## Comments

1,621: 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.

3: : 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

6,349: : : 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.

3: : : : 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

757: : : : : 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:

[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.

[/code]

Phat Nat

1,621