Skip to content

Instantly share code, notes, and snippets.

@ictlyh
Created November 30, 2016 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ictlyh/7404861c1b7f7ba2e1c765e45c872008 to your computer and use it in GitHub Desktop.
Save ictlyh/7404861c1b7f7ba2e1c765e45c872008 to your computer and use it in GitHub Desktop.
List directory recursively on Linux system.
/*
* List directory recursively on Linux system.
* Build: gcc list-dir.c -o list-dir.out
* Run: ./list-dir.out
*/
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
int main (void) {
DIR *dp;
struct dirent *ep;
dp = opendir ("./");
if (dp != NULL) {
while ((ep = readdir(dp))) {
fprintf(stdout, "%d %s\n", ep->d_type, ep->d_name);
}
(void) closedir (dp);
}
else
fprintf(stderr, "Couldn't open the directory");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment