Created
November 30, 2016 09:49
-
-
Save ictlyh/7404861c1b7f7ba2e1c765e45c872008 to your computer and use it in GitHub Desktop.
List directory recursively on Linux system.
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
/* | |
* 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