Solved

Drives

Posted on 1998-08-03
5
156 Views
Last Modified: 2010-05-03
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
0
Comment
Question by:Hanky363
  • 3
5 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1467685
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.
0
 

Author Comment

by:Hanky363
ID: 1467686
I get a "File not found" error. How can I fix it?
0
 

Author Comment

by:Hanky363
ID: 1467687
I am using VB 3.0 16-bit if that makes a difference
0
 

Accepted Solution

by:
vinoopauls earned 50 total points
ID: 1467688
   Put the Drive list box in the form. This will give the list of valid drives in the system.
Scan each drive thru a loop and check for error codes and trap them. The following error codes should help
    57-Device I/O Error
    68-Device Unavailable

Hope this helps
0
 

Author Comment

by:Hanky363
ID: 1467689
cool thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question