finding the right path in the client machine

yaniv

Centurion
Joined
Apr 15, 2002
Messages
167
Location
israel
i need to build an application that find PDF's of news paper aditions. the PDF should stay on the installation CD.
what is the right way to find/ keep the right path in "any machine"? how can i get the right leeter that any user use for his CD drive...

thanks
 
This method can fail if there are multiple CD drives in a machine.

When would be a good idea is to scan each drive, and look for the presence of a particular file in the root of that drive. This should ensure that you can uniquely identify *your* CD. It also handles the fact that your user removed your CD and replaced it with "Goldie Looking Chain's Greatest Hit".

P.
 
concept code, untested.

Visual Basic:
    Dim myDrive As System.IO.DriveInfo = Nothing

    For Each d As System.IO.DriveInfo In My.Computer.FileSystem.Drives
        If d.DriveType = IO.DriveType.CDRom Then
            Dim di As System.IO.DirectoryInfo = d.RootDirectory
            If di.GetFiles("MyUniqueFileName.txt").Length > 0 Then
                myDrive = d
                Exit For
            End If
        End If
    Next

    If myDrive IsNot Nothing Then
        ' Yay! I found the right CD drive, and it contains my CD
        DoSomeStuff()
    Else
        MsgBox("Please insert the application CD-ROM into one of your drives")
    End If
 
This method can fail if there are multiple CD drives in a machine.

When would be a good idea is to scan each drive, and look for the presence of a particular file in the root of that drive. This should ensure that you can uniquely identify *your* CD. It also handles the fact that your user removed your CD and replaced it with "Goldie Looking Chain's Greatest Hit".

P.

The code I posted was a quick example to point him in the right direction - it wasn't meant to be a complete working solution.
 
Last edited:
Back
Top