troubleshooting Question

VB.Net Recurse Subdirectories (permissions?)

Avatar of psyfect
psyfect asked on
Visual Basic ClassicVisual Basic.NET
12 Comments1 Solution832 ViewsLast Modified:
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 & "\")
    End Function

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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 12 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros