Created
December 29, 2013 21:59
-
-
Save rentzsch/8175356 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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