I am using nftw() to do directory traversal. Right now I am only wanting to list out all the files in the directory specified, however it seems to no matter what go down all the folders. It seems that nftw still traverses even if I specify FTW_PHYS.
The only work around is setting up
if (ftwbuf->level > 1) {
return;
}
in the function that gets called. However it is still calling this function on all of these directories.
nftw()enableFTW_ACTIONRETVALin the flags. This enablesnftw()to recourse its execution based on return values fromcallback_function().callback_function()at the beginning itself skip the directory if it's above desired level.Whenever
nftw()returns with a file in a directory crossing theDEPTH_LIMIT,FTW_SKIP_SIBLINGSinstructs it to skip that directory and continue with siblings in parent directory.If you omit
FTW_DEPTHinnftw()flags, you can useFTW_SKIP_SUBTREEfeature; wherenftw()skips a directory right away.FTW_DEPTHinstructsnftw()to pass the directory itself after going through all files & sub-directories in it. Thispost-ordertraversal of directories makes it difficult to useFTW_SKIP_SUBTREE;