Skip to content

Instantly share code, notes, and snippets.

@msg555
Created March 22, 2015 19:58
Show Gist options
  • Save msg555/23e497de6d107f4ee4e2 to your computer and use it in GitHub Desktop.
Save msg555/23e497de6d107f4ee4e2 to your computer and use it in GitHub Desktop.
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
int main(int argc, char** argv) {
for (int i = 1; i < argc; i++) {
DIR* dir = opendir(argv[i]);
if (!dir) {
fprintf(stderr, "failed top open directory %s\n", argv[i]);
continue;
}
for(;;) {
dirent* ent = readdir(dir);
if (ent == NULL) {
break;
}
printf("%s\n", ent->d_name);
}
closedir(dir);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment