hello guys. i got a method that someone showed here BUT it doesnt work 100%... i mean..i put this folder C:\Users\chris\Documents .. if i search for *.docx, it finds only the docx files that are in SUBFOLDERS inside the Documents.. it does NOT find docx files that are in C:\Users\chris\Documents . i tried C:\Users\chris\Documents C:\Users\chris\Documents\ C:\Users\chris\Documents\\ but nothing works(without \ with 1\ and with double\\). then i tried other folders and i see that it doesnt find the files that are in the "root" (for example C:\Users\chris). if i look to C:\Users\chris it will find files that are in SUBFOLDERS inside the chris but not the files that are in chris without subfolders
Private Sub getMyCoolFiles(ByVal selectedDirectoryToSearch As String, ByVal ListBoxForFoundFiles As ListBox)
ListBox1.Items.Clear()
Dim myCoolFolder As New IO.DirectoryInfo(selectedDirectoryToSearch)
For Each foundDirectory In myCoolFolder.GetDirectories '// loop thru all top directories.
Try
'// search top directory and subfolders.
For Each myFoundFile As IO.FileInfo In foundDirectory.GetFiles("*.html", IO.SearchOption.AllDirectories)
ListBox1.Items.Add(myFoundFile.FullName) '// add File to ListBox.
Next
Catch ex As UnauthorizedAccessException
MsgBox(ex.Message) '// display Folders that have been Denied accessed to.
End Try
Next
'MsgBox("Total Files: " & CInt(ListBoxForFoundFiles.Items.Count).ToString("#,###,###")) '// display Total File Count.
End Sub