|
-
Jan 14th, 2005, 01:00 AM
#1
Thread Starter
Fanatic Member
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.
-
Jan 14th, 2005, 01:18 AM
#2
Re: Need help with my recrusive function
Where have you declared FileList?
-
Jan 14th, 2005, 01:25 AM
#3
Thread Starter
Fanatic Member
Re: Need help with my recrusive function
You must have missed it. It's a parameter of thisfunction(). I bet this doesnt work like it did in VB6. But I would like a way to do something similar w/o having to reference some other variable defined in a more global scope.
-
Jan 14th, 2005, 01:33 AM
#4
Re: Need help with my recrusive function
My bad.
I'll go over this again.
-
Jan 14th, 2005, 06:55 AM
#5
Re: Need help with my recrusive function
Hi
You forgot to use the arraylist constructor call.
See modified code
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Files As new ArrayList
thisfunction("c:\test", Files)
MessageBox.Show(Files.Count)
End Sub
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|