Try something like this:

Very basic. Quick and dirty for a project. Works for top two levels only. Will fix to allow variable depth later.

1. Edit $path and $output_path.
2. Put on your web server and run in browser.
3. Retrieve your big-ass CSV file from $output_path.

Edit line 22 to change the output to whatever. Couldn't be arsed to use fputcsv() but it would be simple enough to do.