Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Created February 8, 2018 23:07
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 Rich-Harris/80d739fb5722f47e34a8fbdb5af5f944 to your computer and use it in GitHub Desktop.
Save Rich-Harris/80d739fb5722f47e34a8fbdb5af5f944 to your computer and use it in GitHub Desktop.
simple ls replacement for very large directories
#include <stdio.h>
#include <dirent.h>
int main (int argc, char *argv[ ])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2) {
fprintf(stderr, "usage: ls directory_name\n");
return 1;
}
if ((dp = opendir(argv[1])) == NULL) {
perror("can't copen");
return 2;
}
while((dirp = readdir(dp)) != NULL)
printf("%s\n", dirp->d_name);
closedir(dp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment