finding the right path in the client machine

yaniv

Well-known member
Joined
Apr 15, 2002
Messages
162
Location
israel
i need to build an application that find PDFs 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
 
Code:
If My.Computer.FileSystem.Drives(0).DriveType = IO.DriveType.CDRom Then

End If

sometimes the intellisense is a bit quicker than asking ;)
 
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 Chains Greatest Hit".

P.
 
concept code, untested.

[VB]
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
[/VB]
 
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 Chains Greatest Hit".

P.

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