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

- All Categories 139.8K
- Programming Languages 104K
- Assembler Developer 6.2K
- Basic 1.8K
- C and C++ 39.7K
- C# 4.2K
- Delphi and Kylix 7.9K
- Haskell 3
- Java 9.5K
- Pascal 4.1K
- Perl 1.3K
- PHP 1.9K
- Python 500
- Ruby 47
- VB.NET 4.3K
- VBA 1.6K
- Visual Basic 20.8K
- Game programming 2.6K
- Console programming 308
- DirectX Game dev 87
- Minecraft 1
- Newbie Game Programmers 107
- Oculus Rift 2
- Applications 8.8K
- Computer Graphics 1.8K
- Computer Hardware 721
- Database & SQL 3.4K
- Electronics development 517
- Matlab 1.6K
- Sound & Music 625
- XML Development 253
- Classifieds 3.2K
- Co-operative Projects 184
- For sale 161
- FreeLance Software City 188
- Jobs Available 1.9K
- Jobs Wanted 597
- Wanted 192
- Microsoft .NET 2.8K
- ASP.NET 1.7K
- .NET General 1.1K
- Miscellaneous 2.8K
- Join the Team 2
- User Profiles 1
- Comments on this site 351
- Computer Emulators 54
- General programming 1.7K
- New programming languages 114
- Off topic board 591
- Mobile & Wireless 146
- Android 20
- Palm Pilot 124
- Multimedia 334
- Demo programming 151
- MP3 programming 183
- Bash scripts 0
- Cloud Computing 10
- FreeBSD 52
- LINUX programming 1.7K
- MS-DOS 361
- Shell scripting 0
- Windows CE & Pocket PC 317
- Windows programming 4.1K
- Software Development 870
- Algorithms 400
- Object Orientation 67
- Project Management 80
- Quality & Testing 87
- Security 230
- WEB-Development 7.3K
- Active Server Pages 1.8K
- AJAX 61
- Bootstrap Themes 1
- CGI Development 55
- ColdFusion 19
- Flash development 221
- HTML & WEB-Design 1.4K
- Internet Development 1.3K
- JavaScript 2.2K
- JQuery 33
- WEB Servers 275
- WEB-Services / SOAP 100

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.

Tweets by @pheaven
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

{ 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 D:}

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

About & Contact / 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 LLC

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

## Comments

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

- Spam

0 · Vote Down Vote Up ·3Member: : 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

- Spam

0 · Vote Down Vote Up ·6,349Member: : : 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.

- Spam

0 · Vote Down Vote Up ·3Member: : : : 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

- Spam

0 · Vote Down Vote Up ·757Member: : : : : 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

- Spam

0 · Vote Down Vote Up ·1,621Member- Spam

0 · Vote Down Vote Up ·