Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traverse Directory Depth First

Tags:

c

posix

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:

like image 903
user975582 Avatar asked Nov 27 '25 01:11

user975582


1 Answers

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.

like image 54
Fred Foo Avatar answered Nov 28 '25 16:11

Fred Foo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!