ok, i was not sure what you meant by program, i see now that you were referring to the ftw function..
i have never used it till now, but here is a trivial example (you asked for trivial)..
Code:
#include <stdio.h>
#include <ftw.h>
int print_path(const char* file, const struct stat* sv, int flag)
{
printf("Found %s which is a %s\n",
file, (flag==FTW_F?"file":(flag==FTW_D?"directory":"not a file or directory")));
return 0;
}
int main()
{
ftw("/tmp/s", print_path, 0);
return 0;
}
i just created a simple dir structure in tmp and the result of that program is this
Code:
Found /tmp/s which is a directory
Found /tmp/s/t which is a directory
Found /tmp/s/t/u which is a directory
Found /tmp/s/t/u/v which is a directory
Found /tmp/s/t/u/v/w which is a directory
Found /tmp/s/t/u/v/w/x which is a directory
Found /tmp/s/t/u/v/w/y which is a directory
Found /tmp/s/t/u/v/w/z which is a directory
Found /tmp/s/t/u/v/w/z/z_file1 which is a file
Found /tmp/s/t/u/v/w/z/z_file2 which is a file
Found /tmp/s/t/u/v/w/z/z_file3 which is a file
Found /tmp/s/t/u/v/w/z/z_file4 which is a file
which is accurate to what i created.. it seems pretty simple to use.. if you want to see the
stat structure do a `man 2 stat`
hth