in reply to search for folder

I admit I have not tried running your code, but I will make the following suggestions, which I strongly suspect will lead you to your answer:

I say this because I noticed that in your main routine you perform an opendir() and die() on error with a custom error message, ans in your godeep() routine you perform an opendir() and assume success.

Hope that helps.