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




Reply With Quote