Results 1 to 5 of 5

Thread: Need help with my recrusive function

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Need help with my recrusive function

    I am trying to write a recursive function to return a list of files within folders and subfolders of a given directory.

    I get the error, Object reference not set to an instance of an object, when I do FileList.Add.

    Code:
      Function thisfunction(ByVal path As String, ByVal FileList As ArrayList)
            Dim di As New DirectoryInfo(path)
            Dim folder As DirectoryInfo
            Dim folders() As DirectoryInfo
            Dim file As FileInfo
            Dim files() As FileInfo
    
    
            folders = di.GetDirectories()
    
            For Each folder In folders
                thisfunction(path & "\" & folder.Name, FileList) 
            Next
    
            files = di.GetFiles
    
            For Each file In files
                FileList.Add(path & "\" & file.Name) '-capture currentworking path & filename
            Next
    
        End Function
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim Files As ArrayList
    
            thisfunction("c:\test", Files)
    
            MessageBox.Show(Files.Count)
        End Sub
    Last edited by nkad; Jan 14th, 2005 at 01:14 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width