Index SD Card?!

Well, there's two main ways of doing it. You have the basics there with that function - it gets the files and directories for a given folder. The simplest, though most memory intensive, way of expanding it would be to use recursion - whenever it finds a directory in its list, instead of just adding it to the array, it calls the same function again but with the directory as its parameter. You may want to expand the function to take a path prefix to prepend to the names for you.

The better way would be to do it iteratively, where you maintain a stack of directories to scan, and whenever you find a directory you push it onto the stack, then when the current directory is finished you pop a folder off the stack and scan that. Uses less memory that recursion, but is harder to program.