|
-
Nov 12th, 2001, 12:30 AM
#1
Thread Starter
Frenzied Member
Recursive File List function
I have a function that will return any files in a given folder. But in order to make it also return files in subfolders, i was told i would have to make it recursive. Recursive functions are something ive never had to use yet...and quite frankly i dont understand them. Could someone tell me what modifications i would have to make to this function to make it return subfolder files as well?
VB Code:
Function DirList(strDir As String) As String()
'returns a 0 based array with the files in strDir
'Can contain a pattern such as "*.*"
Dim Count As Integer
Dim sFiles() As String
Dim sFile As String
sFile = Dir$(strDir)
Count = -1
Do
Count = Count + 1
ReDim Preserve sFiles(Count)
sFiles(Count) = sFile
sFile = Dir$
Loop
DirList = sFiles
End Function
thanks,
Nishant
You just proved that sig advertisements work.
-
Nov 12th, 2001, 12:39 AM
#2
Hyperactive Member
recursive function is a function which calls itself untill a break condition.
you must check whether file u have searched is a dirctory and if it is a dirctory, call your function again with new dirctory name. repeat this untill all the files have been searched.
u must provide a break condition for recursive funtion otherwise it is a infinite loop
-
Nov 12th, 2001, 12:47 AM
#3
Thread Starter
Frenzied Member
I see...could you post an example of a recursive function so i can look at it? I almost get the idea....but im not quite there. The calling itself thing just doesnt click in.
You just proved that sig advertisements work.
-
Nov 12th, 2001, 12:55 AM
#4
Hyperactive Member
i havent used recursive funtion in vb though
simple example would belike finding a factorial of a number
private function factorial(n as long,ans as long) as long
if n = 1 then
factorial = ans ' Check for break condition
else
ans = n * (n-1)
factorial (n-1,ans) ' This is where a recursive call is made
endif
end funtion
-
Nov 12th, 2001, 01:21 AM
#5
Thread Starter
Frenzied Member
I think i understand...but how would i implement that into my File-Listing function?
You just proved that sig advertisements work.
-
Nov 12th, 2001, 01:42 AM
#6
Hyperactive Member
-
Jul 5th, 2002, 05:22 AM
#7
Frenzied Member
Heres an example of a recursive function.
VB Code:
Function Down2One(Number)
Down2One = Number - 1
Do Until x < 1
Down2One = Down2One(Number - 1)
Loop
End Function
What that function does is call itself over and over decreasing
number by 1 each time until it is less than 1
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
|