How to access files on a cd using IO.StreamReader

  • Thread starter Thread starter Dennis
  • Start date Start date
D

Dennis

I want to have my program look on the CD drive for the data files
needed to run my program but I can't find any info on this. I am using
a StreamReader to get really simple information from a text file and I
want it to look on the CD Drive. As computers have many drives is
there a way I can have it look on the first CD Drive. When declare it,
it looks like this but I was hoping I could change the file spec. Dim
varReader As IO.StreamReader = IO.File.OpenText("A:\Data.txt") Does
this make sense and does anyone have any ideas about this?

Thanks for the help, Dennis
 
Hi Dennis,
Take a look at the OpenFileDialog class on MSDN,
After you have found a file with that it becomes something like
varReader As IO.StreamReader = IO.File.OpenText(myOpenFileDialog.file)

I hope it brings you on the route.

Cor
 
Thanks for replying but that doesn't really help. I just wanted the
streamreader to look in the first cd drive, whatever that might be
depending on the computer reading it, and open the data file. I was
thinking about something like ...

IO.StreamReader = IO.File.OpenText("%FirstCdDrive%\Data.txt")

Thanks for the feedback, always helpful.

Cheers, Dennis
 
Hi Dennis,

I had saved something Herfried has made for showing drives.
I changed it and I think it will work.
Try it yourself.

Set a Reference to:
Set a reference to .Net System.Management

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Dim allDrives() As String = Environment.GetLogicalDrives()
Dim drive As String
Dim sr As System.IO.StreamReader
For Each drive In allDrives
Dim win32Drive As String = _
"Win32_LogicalDisk='" & drive.Substring(0, 2) & "'"
Dim moDisk As System.Management.ManagementObject _
= New System.Management.ManagementObject(win32Drive)
If moDisk("DriveType").ToString = "5" Then
Try
sr = New System.IO.StreamReader(drive & "\Data.txt")
Exit For
Catch ex As Exception
MessageBox.Show(ex.tostring)
End Try
End If
Next

I hope this helps a little bit
Cor
 
Thanks, that does help a lot but it's a bit out of my skill level. I
was hoping there was an easy way to do this but I guess not. I'm doing
this for school so I don't want to add other peoples work.

Thanks again, that really does help.

Cheers, Dennis
 
Back
Top