In Visual Basic How do I find one of my files on a CD/DVD

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi Good People
I have Lots Of CD/DVD with my own files on them, But how can I search For a file on my CD/DVDs. My files can also be on a flash drive. I need to write code for Button3 that shows the result in textbox2 for the file I am looking for.
the code I have below already, is to search for drives. and once found, I double click on a Particular drive and type into textbox1 the file I am looking for. and once found the result put into textbox2 of the particular file that is found.
some of the files are scans of documents. letters pictures. here is the code I have already:Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListView1.Items.Clear()
Dim i As Integer = 0
For Each drive As IO.DriveInfo In IO.DriveInfo.GetDrives
Dim itemText As String = drive.Name
Dim Type As String
Dim ltr As String = drive.Name
If drive.IsReady AndAlso drive.VolumeLabel <> "" Then
itemText = drive.VolumeLabel
Else
Select Case drive.DriveType
Case IO.DriveType.Fixed : itemText = "Local Disk"
Case IO.DriveType.CDRom : itemText = "CD-ROM"
Case IO.DriveType.Network : itemText = "Network Drive"
Case IO.DriveType.Removable : itemText = "Removable Disk"
Case IO.DriveType.Unknown : itemText = "Unknown"
End Select
End If
Select Case drive.DriveType
Case IO.DriveType.Fixed : Type = "Local Disk"
Case IO.DriveType.CDRom : Type = "CD-ROM"
Case IO.DriveType.Network : Type = "Network Drive"
Case IO.DriveType.Removable : Type = "Removable Disk"
Case IO.DriveType.Unknown : Type = "Unknown"
End Select
ListView1.Items.Add(itemText)
ListView1.Items(i).SubItems.Add(ltr)
ListView1.Items(i).SubItems.Add(Type)
i += 1
Next
End Sub
Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
Dim SelItem As String = ListView1.SelectedItems(0).SubItems(1).Text
For Each drive As IO.DriveInfo In IO.DriveInfo.GetDrives
Try
Process.Start(SelItem)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "ERROR")
End Try
Next
End Sub
Private Sub ListView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListView1.KeyDown
If e.KeyCode = Keys.Enter Then
Dim SelItem As String = ListView1.SelectedItems(0).SubItems(1).Text
For Each drive As IO.DriveInfo In IO.DriveInfo.GetDrives
Try
Process.Start(SelItem)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "ERROR")
End Try
Next
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListView1.Items.Clear()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class
Can someone point me in the right direction please
Kind Regards
Gary
Gary Simpson

View the full article
 
Back
Top