Dirve - Programmers Heaven

#### Howdy, Stranger!

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

# Dirve

Posts: 10Member
I need a routine to find out how many drives has a pc and which is the drive letter.

Thank you

• Posts: 6,349Member
@1: XCHG AX,CX { Put the return value into AX }
end;
[/code]
• Posts: 757Member
: I need a routine to find out how many drives has a pc and which is the drive letter.
:
: Thank you

I've used this one. Not only does it tell you if the drive exists (Size > 0) but it tells you the drive size (up to 2.1 Gigs). Doesn't include CD-ROM drives (I don't know about burners).

Phat Nat

[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
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
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]
• Posts: 10Member
: : I need a routine to find out how many drives has a pc and which is the drive letter.
: :
: : Thank you
:
:
: I've used this one. Not only does it tell you if the drive exists (Size > 0) but it tells you the drive size (up to 2.1 Gigs). Doesn't include CD-ROM drives (I don't know about burners).
:
: Phat Nat
:
: [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
: 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
: 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]
:

Thank you, but i need a function that checks if the drive exist.
That means, that i want to know: Has the PC a disketten Drive or cdrom drive or a harddisk.
And than i need the first driveletter.

Ciao