Recursive search to a file

Hello people

I’m losing it, I’m breaking myself over the recursive search.
The goal is, give a parameter a name, for example “test”, and this function searches a file in a bunch of folders, named “test.block”

atm, I have this:

[code]Function SearchBlockInFolder(blockName As String, optional fi As FolderItem) As FolderItem
Dim i As Integer
Dim f As FolderItem
If fi = Nil Then
f = GetBlocksFolder
Else
f = fi
End If

For i = 1 To f.Count
If f.TrueItem(i).Directory then
Dim foundBlock As FolderItem
foundBlock = SearchBlockInFolder(blockName)
If foundBlock <> Nil Then
Return foundBlock
End If
ElseIf NthField(f.TrueItem(i).DisplayName, “.”, 0) = blockName And NthField(f.TrueItem(i).DisplayName, “.”, 1) = “block” Then
Return f
End If
next
End Function
[/code]

It justs keeps running. I looked too long at this code. Can someone give me an insight on what is going wrong here?

Thanks a lot.

The problem is in this line:

      foundBlock = SearchBlockInFolder(blockName)

You want to search the subdirectory there but never provide the second parameter, so it goes into an endless loop of searching the same base folder.

Thanks Mr Tekinay!

And there were a few other problems:
-NthField is 1 based, not 0 based like my code
-The last return in my code should be f.TrueItem(i), not f