ftw function

int ftw(const char *path, int(*func)(), int depth);

what does the third parameter(depth) mean?
the book said that the larger the value of depth, the fewer directories have to be reopened, therefore increasing the speed of the call.
how so?
thanks

Suppose you have this:
/dir1
/dir1/file1
/dir1/dir2
/dir1/dir2/filex
/dir1/file2

ftw first will open /dir1 and start reading it. When it comes to dir2, now it need to open that. If depth is 1, it will close dir1, open dir2 and process dir2. Then it needs to finish /dir1, so it reopens it.

If you set depth to two, you are telling it that it can have two directories open at once. So it doesn't need to close dir1 to handle dir2.