troubleshooting Question

Recursive list of files in folder and all subfolders

Avatar of scottealam
scottealamFlag for New Zealand asked on
3 Comments1 Solution1025 ViewsLast Modified:
Again - a newbie to ASP.NET I got some help with this question last week but another question has cropped up as a result.
I'm trying to get a list of all the files in a folder and all the files in all subfolders beneith it. I thought the code below would do the trick, but it doesn't seem to work quite right. It is listing the files in all the subfolders, but not the files within the top level folder and doesn't seem to look any deeper than one subfolder. Here is the code

Private Sub OnNodeSelect(ByVal virtualFolderPath As String)
        Dim Directories As New DirectoryInfo(virtualFolderPath)
        Dim Directory As DirectoryInfo
        Dim File As FileInfo
        Dim dt As New DataTable
        Dim dr As DataRow      

        For Each Directory In Directories.GetDirectories
             For Each File In Directory.GetFiles
                dr = dt.NewRow
                dr("Name") = File.Name
                dr("FullName") = File.FullName
                dr("LastWriteTime") = File.LastWriteTime

             If Directory.GetDirectories.Length > 0 Then
             End If

         FileList.DataSource = dt
         End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 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 3 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