Finding out what drives I have

aziz rasul

Active member
Local time
Today, 12:08
Joined
Jun 26, 2000
Messages
1,935
I have extracted the following code from online help (Drives Property). Online help suggests that even are no media in any of the drives, the code should work. But it doesn't.

How do I amend the code so that, for example there is no floppy disk in the A:\ drive, the code wil recognise that the drive exists and not cause an error saying that "Disk not ready".

Note that the code may be used on other machines which potentially will differenr drives e.g. 2 CD drives.

Public Function FolderInformation(strFolderName As String)

Dim fso As Object
Dim f As Object
Dim Drive_Message As String
Dim dc As Object
Dim n As String
Dim d As Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(strFolderName)
Set dc = fso.Drives

For Each d In dc
Drive_Message = Drive_Message & d.DriveLetter & " - "
If d.DriveType = 3 Then
n = d.ShareName
Else
n = d.VolumeName
End If
Drive_Message = Drive_Message & n & vbCrLf
Next

MsgBox Drive_Message, vbOKOnly, "Drive List"

End Function
 
Try This :-

Public Function FolderInformation()

Dim fso As Object
Dim Drive_Message As String
Dim dc As Object
Dim n As String
Dim d As Object

On Error GoTo diskerror

Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives

For Each d In dc
Drive_Message = Drive_Message & d.DriveLetter & " - "
If d.DriveType = 3 Then
n = d.ShareName
Else
n = d.VolumeName
End If
Drive_Message = Drive_Message & n & vbCrLf
Next

MsgBox Drive_Message, vbOKOnly, "Drive List"

diskerror:

If err.Number = 71 Then 'Trap the "Drive Not Ready" Error.
'MsgBox "no disk in floppy"
Resume Next
End If

End Function
 
Many thanks.

Is there a way of writing code that recognises what kind of drive I have e.g. A:\ as a floppy drive, G:\ as a CD ROM drive, etc.
 
Just add d.DriveType to your MsgBox line, or specify what sort of Drive you want in the Code (it is currently set to 3).

Drive types are as follows :-

0 = "Unknown"
1 = "Removable"
2 = "Fixed"
3 = "Network"
4 = "CD-ROM"
5 = "RAM Disk"
 
That's of great help.

Found some code relating to what I'm doing. KB 180766 at http://support.microsoft.com/defaul...ben-us;180766

The code mentions Public Const DRIVE_CDROM As Long = 5

However in my code, the Drive Type for a CD-ROM is 4?

What's the difference? Both pieces of code work.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom