Hi, i've just got a quick question. I've got a small app that I'm using to search for either specific files or files of a certain type. Thats not really the important part. The problem arises when i search for files by type, it returns a long list and populates a richtextbox lstBooks, it returns a long list (2149 i think) but it only displays the last part of the list. Whats the way around this?
CODE
Private Sub btnDirectories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDirectories.Click
Dim drivestring As String = txtDrive.Text + ":\"
Try
listDirectories(drivestring)
Catch ex As Exception
MessageBox.Show("Invalid drive", "Tool", MessageBoxButtons.OK, MessageBoxIcon.Hand)
MessageBox.Show("Exception thrown: " & ex.Message)
End Try
End Sub
'Sub routine
'Run on click of btnListDirectories
'
'Displays all directories on drive
'
'Args: drive as String, name of drive to search
'
'Populates list box lstDirectories
'
'Calls Function searchForFiles on each execution of loop
Private Sub listDirectories(ByVal drive As String)
'List each folder at the root of specified drive
For Each strFolder As String In My.Computer.FileSystem.GetDirectories(drive)
'Add the item to the list
lstData.Items.Add(strFolder)
If strFolder <> "d:\System Volume Information" Then
'Search for books in directory
'Me.lstBooks.Text = Me.SearchForFiles(strFolder, FileIO.SearchOption.SearchAllSubDirectories, "*.txt")
Me.rtbTempBookList.Text = Me.SearchForFiles(strFolder, FileIO.SearchOption.SearchAllSubDirectories, "*.pdf")
End If
Next
'Temporary message show number of returned files
MessageBox.Show(tempCount)
End Sub
'Function
'Run on each execution of loop in Sub listDirectories
'
'Displays all books, documents matching criteria
'
'Args: directory as string, name of directory to search
' searchOption as Microsoft.VisualBasic.FileIO.SearchOption, depth of search
' wildcards as string, any criterion the search needs to match
'
'Populates list box lstBooks
'
'Returns: returnValue as String, file names of files matching criteria
Protected Function SearchForFiles(ByVal directory As String, ByVal searchOption As Microsoft.VisualBasic.FileIO.SearchOption, ByVal wildCards As String) As String
Dim returnValue As String = ""
Try
For Each foundFile As String In My.Computer.FileSystem.GetFiles(directory, searchOption, wildCards)
returnValue &= foundFile & Environment.NewLine
tempCount = tempCount + 1
Next
Catch ex As Exception
MessageBox.Show("Exception thrown: " & ex.Message)
End Try
Return returnValue
End Function