Skip to content

Instantly share code, notes, and snippets.

@rentzsch
Created December 29, 2013 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rentzsch/8175356 to your computer and use it in GitHub Desktop.
Save rentzsch/8175356 to your computer and use it in GitHub Desktop.
#include <stdio.h> // for fprintf, stderr, perror
#include <stdlib.h> // for exit() and EXIT_FAILURE
#include <errno.h> // for errno
#include <fts.h> // for fts
int main(int argc, const char *argv[]) {
char * const paths[] = {"/tmp", NULL};
FTS *tree = fts_open(paths, FTS_COMFOLLOW|FTS_NOCHDIR, NULL);
if (!tree) {
perror("fts_open");
exit(EXIT_FAILURE);
}
FTSENT *node;
while ((node = fts_read(tree))) {
switch (node->fts_info) {
case FTS_D:
printf("d %s\n", node->fts_path);
break;
case FTS_F:
printf("f %s\n", node->fts_path);
break;
default:
break;
}
}
if (errno) {
perror("fts_read");
exit(EXIT_FAILURE);
}
if (fts_close(tree) == -1) {
perror("fts_close");
exit(EXIT_FAILURE);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment