I am trying to write a program to walk the directory tree (millions of files and directories) and exclude any directory that is named ".snapshot".

However, whenever a ".snapshot" directory is encountered, nftw stops instead of continuing to the next directory. Any suggestions would be appreciated.

I am running "Red Hat Enterprise Linux Server release 6.1 (Santiago)".
I am using gcc "gcc version 4.4.5 20110214 (Red Hat 4.4.5-6) (GCC)"

My code is as follows:

#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <stdio.h>
#include <ftw.h>

static int
chuid(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
char *fname = basename(fpath);

printf("fname = %s; fpath = %s; tflag = %d\n", fname, fpath, tflag);

if ( (strcmp(fname, ".snapshot")) == 0 )

return FTW_CONTINUE; /* To tell nftw() to continue */

int flags = 0;

flags |= FTW_PHYS; /* do depth first traversal and don't follow sym links */

/* walk the directory tree */
nftw("testdir", chuid, 20, flags);

return 0;