I am attempting to identify all subdirectories within a user-specified path on two Operating Systems, Vista and XP. I have two current options. The first one seems to be the best, as it tends to actually read the folders, my problem is that it is broken somehow, and not truly recursive:
Public Function SearchFolders(ByVal path As String) As Long
Dim Dir As New IO.DirectoryInfo(path)
Dim Fils As IO.DirectoryInfo() = Dir.GetDirectories()
Dim Fil As IO.DirectoryInfo
For Each Fil In Fils
SearchFolders(Fil.FullName & "\")
Preferably, I would like to have a functioning version of this code which actually acknowledges all subdirectories. Alternatively, however, I found different code which seems to work flawlessly and is extremely small. The problem, although, appears to be permissions.
The previous code will acknowledge paths below "C:\Users\" on a Vista machine (at least the ones found by the broken code). The following code, however, seems to not have permissions and consequently does not display anything:
Public Function RecursiveFolder(ByVal path As String) As Long
For Each fold As String In My.Computer.FileSystem.GetDirectories(path, FileIO.SearchOption.SearchAllSubDirectories)
If I were to use the above code on a path to an external hard drive, all subdirectories would be acknowledged. Though if I were to chose "C:\Users\" on Vista I get nothing. So while this code would be most efficient for an XP machine with no preset permissions, it is useless for my requirements.