{ 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

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

- 140.8K All Categories
- 103.6K Programming Languages
- 6.4K Assembler Developer
- 401 Assembly Code Share
- 239 Getting started in assembly
- 4.6K x86 Assembly
- 1.9K Basic
- 97 Qbasic
- 39.9K C and C++
- 5.6K Beginner C/C++
- 330 C/C++ on Linux/Unix
- 450 C/C++ Windows API
- 522 C++ Builder
- 253 C++ Game Development
- 3.3K C++ MFC
- 103 C++.NET
- 404 Visual C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 334 Advanced Delphi
- 360 Delphi beginners
- 4 Haskell
- 9.7K Java
- 56 Enterprise JavaBeans
- 1.3K Java Beginners
- 304 Java Server Pages
- 4.1K Pascal
- 1.3K Perl
- 11 Perl 6
- 2K PHP
- 546 Python
- 37 Ruby
- 4.4K VB.NET
- 258 Advanced VB.Net
- 1.6K VBA
- 20.8K Visual Basic
- 767 Access databases and VB
- 831 Advance Visual Basic
- 1.2K Beginner VB
- 2.6K Game programming
- 315 Console programming
- 90 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 279 3D Graphics
- 129 DirectX
- 125 OpenGL
- 740 Computer Hardware
- 9 Cooling & Overclocking
- 3.4K Database & SQL
- 1.1K Access
- 91 ADO Programming
- 288 MySQL
- 358 Oracle
- 440 SQL-Server
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 25 DirectSound
- 257 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 603 Jobs Wanted
- 209 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 22 .NET WEB-Services
- 129 .NET WinForms
- 14 .NET XML
- 50 ADO.NET
- 142 C# & VB.NET School Support
- 3.4K Miscellaneous
- 8 Join the Team
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 621 Off topic board
- 200 Mobile & Wireless
- 72 Android
- 126 Palm Pilot
- 338 Multimedia
- 154 Demo programming
- 184 MP3 programming
- 0 Bash scripts
- 27 Cloud Computing
- 1 Witsbits Go Cloud
- 53 FreeBSD
- 1.7K LINUX programming
- 1 Awk scripting
- 332 Linux Support
- 0 Sed scripting
- 370 MS-DOS
- 0 Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 177 COM/DCOM
- 61 Networking And Security
- 17 Windows 2003 Server
- 6 Windows Vista
- 176 Windows XP
- 939 Software Development
- 416 Algorithms
- 68 Object Orientation
- 24 RUP & UML
- 91 Project Management
- 95 Quality & Testing
- 268 Security
- 63 Evil Scripting
- 81 Hacking
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 4 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 131 Mobile Internet & Messaging
- 211 Wireless development
- 2.2K JavaScript
- 37 JQuery
- 304 WEB Servers
- 153 Apache
- 79 IIS
- 150 WEB-Services / SOAP

## Comments

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

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

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

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

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