wytkat28
06-01-2003, 01:01 PM
I want to use my program to open a file from the cd drive. I also want to use the program on different computers. I know that the drive letter of my computer is different then the other computers. How do I open the file while accounting for the different drive letters?
GavinO
06-01-2003, 02:32 PM
You can ask the user which drive the CD is in. You could also scan all the drives in the system for the file, though if the file name happened to be in the same location on another disk, this could cause a problem (fixable by having a signature at the beginning of the file that you check for). You can get all the drives through a DriveList control.
wytkat28
06-01-2003, 06:58 PM
Why can't I say...
instead of, "D:\text.txt", (that's my cd drive letter) something in the area of, "DRIVE_CDROM:\text.txt" or something along those lines?
OnErr0r
06-01-2003, 07:07 PM
Here is a function to get all the CD Drives on a machine (if any). If an empty string is not returned, then loop through each character of the string and add to a drop down list (much like Gavin suggested) next set the listindex to the first one.
Public Function GetCDS() As String
Dim i As Long
Dim b() As Byte
Dim lPos As Long
Dim lDrives As Long
ReDim b(63) ' max 32 drives (32 bits)
lDrives = GetLogicalDrives() ' bitmask containing drives
If lDrives Then ' just in case the call fails
Do
If (lDrives And 1) Then ' is the bit set?
If GetDriveType(Chr$(i + 65) & ":\") = DRIVE_CDROM Then
b(lPos) = i + 65 ' convert to ascii
lPos = lPos + 2 ' unicode so skip two
End If
End If
i = i + 1 ' increment counter
lDrives = lDrives \ 2 ' shift right
Loop While lDrives
ReDim Preserve b(lPos - 1) ' don't want trailing nulls
GetCDS = b ' vb copies to a unicode string
End If
End Function
GavinO
06-01-2003, 07:38 PM
The reason that there is no system variable by default is that systems may have any number of drives of any type (well, two floppies is the limit there, but anyway) so just CD_DRIVE would not be tremendously useful. You do get the collection of drives presented as shown in the example, tho.
wytkat28
06-01-2003, 09:14 PM
cool thanks bunches everyone...I find now that I don't know how to take those found directories and search them for my file, then open that file...please help
OnErr0r
06-01-2003, 09:29 PM
You can call Dir$ in a loop to enunerate all the files in a directory. Or even write a recursive procedure to enum sub dirs/files. Opening a file requires an Open Statement. Search the forum, you'll see it mentioned repeatedly.