开发者

Traverse Directory Depth First

开发者 https://www.devze.com 2023-04-10 06:47 出处:网络
I need to traverse a directory depth first without using boost but I have not been able to find 开发者_Go百科a good tutorial how to do this. I know how to list the files of the directory, but not sure

I need to traverse a directory depth first without using boost but I have not been able to find 开发者_Go百科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:


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号