title: Skip subdirectories when using ntfw in c
body: <p>I am trying to get all the files and directories in the current or mentioned folder using <a href="http://linux.die.net/man/3/nftw" rel="nofollow">nftw</a>. But how do I instruct the function not to go further in any subdirectory? What is the purpose of the flag <code>FTW_SKIP_SUBTREE</code>? Also what is the header file for this constant. </p>
  
  <pre><code>#include &lt;ftw.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdint.h&gt;
  
  static int
  display_info(const char *fpath, const struct stat *sb,
               int tflag, struct FTW *ftwbuf)
  {
  
      printf("%-3s %2d %7jd   %-40s %d %s\n",
          (tflag == FTW_D) ?   "d"   : (tflag == FTW_DNR) ? "dnr" :
          (tflag == FTW_DP) ?  "dp"  : (tflag == FTW_F) ?   "f" :
          (tflag == FTW_NS) ?  "ns"  : (tflag == FTW_SL) ?  "sl" :
          (tflag == FTW_SLN) ? "sln" : "???",
          ftwbuf-&gt;level, (intmax_t) sb-&gt;st_size,
          fpath, ftwbuf-&gt;base, fpath + ftwbuf-&gt;base);
      return 0;           /* To tell nftw() to continue */
  }
  
  int
  main(int argc, char *argv[])
  {
      int flags = 0;
  
      if (argc &gt; 2 &amp;&amp; strchr(argv[2], 'd') != NULL)
        flags |= FTW_DEPTH;
      if (argc &gt; 2 &amp;&amp; strchr(argv[2], 'p') != NULL)
        flags |= FTW_PHYS;
      if (argc &gt; 2 &amp;&amp; strchr(argv[2], 's') != NULL)
        flags |= FTW_SKIP_SUBTREE;
  
      if (nftw((argc &lt; 2) ? "." : argv[1], display_info, 20, flags)
              == -1) {
          perror("nftw");
          exit(EXIT_FAILURE);
      }
      exit(EXIT_SUCCESS);
  }
  </code></pre>
  
  <p>When I try to compile I get this message </p>
  
  <pre><code>test.c:33:16: error: ‘FTW_SKIP_SUBTREE’ undeclared (first use in this function)
         flags |= FTW_SKIP_SUBTREE;
  </code></pre>