Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'starting path
Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sPathDI As New IO.DirectoryInfo(sPath) 'as directory info
Dim allDirs As New List(Of IO.DirectoryInfo) 'list of all directories
allDirs.Add(sPathDI) 'add starting point
allDirs.AddRange(GetDirs(GetSubDirs(sPathDI))) 'add ALL the sub dirs
'at this point you have all the directories
'place code to get files here
End Sub
Private Function GetDirs(ByVal theDirs As List(Of IO.DirectoryInfo)) As List(Of IO.DirectoryInfo)
'add directories. called recursively.
Dim rv As New List(Of IO.DirectoryInfo)
For Each di As IO.DirectoryInfo In theDirs
rv.Add(di)
Dim foo As List(Of IO.DirectoryInfo) = GetDirs(GetSubDirs(di))
rv.AddRange(foo)
Next
Return rv
End Function
Private Function GetSubDirs(ByVal theDir As IO.DirectoryInfo) As List(Of IO.DirectoryInfo)
Dim theSubDirs As New List(Of IO.DirectoryInfo)
Try
theSubDirs.AddRange(theDir.GetDirectories.ToList) 'get dirs in the current folder
Catch SecEx As UnauthorizedAccessException
'do nothing with security exceptions
End Try
Return theSubDirs
End Function
Note: Lengthy process. I'd experiment with just MyDocuments before trying an entire hard drive...
From my own experience of displaying progress while the "engine" runs and all that fun stuff took me over 1000 lines of code.
Trust me not that easy to do.