Link to home
Start Free TrialLog in
Avatar of Hanky363
Hanky363

asked on

Drives

In my program, I need to run a scan on all drives available on a system. How do I figure out which drives are there or not? For Floppy disk drives and CD ROM Drives I need to check if it is accessable, or disk loaded into it. Thanks for your help
Avatar of shchuka
shchuka

You need to use the GetDriveType API call:

Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Then you can do something like this:
dim d as integer
dim s as string
dim r as long
for d=0 to 25
    ' here 0 means drive A:, 1 is drive B:, etc...
    s = chr$(d+65) & ":"
    r = GetDriveType(s);
    if r = 2 then
        ' This is a removable drive (floppy, ZIP, etc...)
    elseif r = 3 then
        ' This is a hard drive
    elseif r = 4 then
        ' This is a network drive
    elseif r = 5 then
        ' This is a CD-ROM drive
    elseif r = 6 then
        ' This is a virtual RAM drive
    else
        ' Drive does not exist
    end if
next d

To check whether, for example a diskette is in a floppy drive, you can try reading a directory from that diskette (say, dir *.*) and catch the errors.  If an error occurs, then there is no diskette in the drive.
Avatar of Hanky363

ASKER

I get a "File not found" error. How can I fix it?
I am using VB 3.0 16-bit if that makes a difference
ASKER CERTIFIED SOLUTION
Avatar of vinoopauls
vinoopauls

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
cool thanks