Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB.NET
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim path As String = FolderBrowserDialog1.SelectedPath
    Dim di As New DirectoryInfo(path)
    Dim yourSearchString As String
    yourSearchString = "my string"
    For Each Dir As String In Directory.GetDirectories(FolderBrowserDialog1.SelectedPath)
        ListBox1.Items.Clear()
        ListBox2.Items.Add(Dir)
    Next
    For Each fi As FileInfo In di.GetFiles()
        If File.ReadAllText(fi.FullName).Contains(yourSearchString) Then
            Console.WriteLine(fi.Name)
            ListBox1.Items.Add(fi.Name)
        End If
    Next
End Sub


What I have tried:

I want search a string in more file, and my code can search in one folder good, but i want this search in sub-folder in folder root.!
Who can help me, Please!!
Posted
Updated 5-Sep-16 4:51am

 
Share this answer
 
Comments
Le Van Phu 5-Sep-16 1:08am    
i know! however u can code help me for this.? help me.
i code,but this not search in sub-folder.
Le Van Phu 5-Sep-16 1:10am    
and this KB for "Search file name" , i need search contain
Mehdi Gholam 5-Sep-16 1:14am    
The code show how to recursively go down the folders, change it to do search.
Le Van Phu 5-Sep-16 1:24am    
but i dont know how to do, :(( help me! please!!
Le Van Phu 5-Sep-16 4:18am    
help me....!!!
 
Share this answer
 
Comments
Mehdi Gholam 5-Sep-16 11:19am    
5'ed
Maciej Los 5-Sep-16 13:50pm    
Thanks, Mehdi.
Maciej Los 5-Sep-16 13:50pm    
--
Try this
Directory.GetFiles(FolderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories)
 
Share this answer
 
Comments
Le Van Phu 5-Sep-16 22:24pm    
i want search contain file it not search name and format file.
i want search a text file in a folder and sub-folder.
help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900