if you are using vb 2005 then here it is
Code: VB
Dim SearchCriteria As String = String.Empty ' Globals
Dim FileFound As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
FileFound = 0 ' reset counter
MessageBox.Show("Number of files matching : " + GetFileCount(TextBox2.Text).ToString())
Catch ex As Exception
MessageBox.Show("Error occured: " + ex.Message)
End Try
End Sub
Private Function GetFileCount(ByVal path As String) As Integer
Dim CriteriaPath, files, dirs As String
CriteriaPath = path.Substring(0, path.LastIndexOf("\"))
If SearchCriteria.Length = 0 Then
SearchCriteria = "*.*"
Else
SearchCriteria = path.Substring(path.LastIndexOf("\") + 1)
End If
For Each files In Directory.GetFiles(CriteriaPath, SearchCriteria)
FileFound += 1
Next
For Each dirs In Directory.GetDirectories(CriteriaPath)
GetFileCount(dirs + "\" + SearchCriteria) ' recursive call
Next
Return FileFound
End Function