This sounds to me like a classic recursion problem. The
trick is to have one function you call on a directory which
goes throught the listing, calling itself for each
directory found. This should should allow you to traverse
an entire directory tree without any trouble.