Reputation: 205
I need to traverse a directory depth first without using boost but I have not been able to find a good tutorial how to do this. I know how to list the files of the directory, but not sure how to about this one. This list the files of a directory:
Upvotes: 3
Views: 528
Reputation: 31182
Make sure you understand recursion.
I assume you have a function walk(dir_path)
which can list all files (and directries) in the dir_path directory. You need to modify it, so it calls it self (recursively) for each directory you find. That's it.
Upvotes: 0
Reputation: 363737
Use the ftw
or nftw
functions if your system has them. Or, grab the fts_*
functions from, e.g., the OpenBSD source tree and study those, or use them directly. This problem is harder than you might think, because you can run out of file descriptors when recursing through deep filesystem hierarchies.
Upvotes: 1