Click to See Complete Forum and Search --> : access files on unknown CD drive


tawnya
January 18th, 2000, 01:06 PM
I have a form with 3 buttons that access files on a cd. How do I read files from the cd? Keep in mind I don't know what drive letter the user has assigned to the cd drive and they could have more then one. Hope that makes sense.

Aaron Young
January 18th, 2000, 02:46 PM
You can use a Couple of APIs to determine which Drive is the CDROM, ie.

private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (byval nDrive as string) as Long
private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (byval nBufferLength as Long, byval lpBuffer as string) as Long
private Const DRIVE_CDROM = 5

Function FindCDROM() as string
Dim sDrives as string
Dim sDrive as string

sDrives = Space(255)
sDrives = Left$(sDrives, GetLogicalDriveStrings(255, byval sDrives))
While InStr(sDrives, "\")
sDrive = Left$(sDrives, InStr(sDrives, "\"))
If GetDriveType(sDrive) = DRIVE_CDROM then
FindCDROM = sDrive
Exit Function
End If
sDrives = mid$(sDrives, len(sDrive) + 2)
Wend
End Function

private Sub Command1_Click()
Debug.print "CDROM is on Drive - " & FindCDROM
End Sub





Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com