Skip to content

Instantly share code, notes, and snippets.

@markogresak
Created January 30, 2015 15:00
Show Gist options
  • Select an option

  • Save markogresak/6b25a99108a04df02f0b to your computer and use it in GitHub Desktop.

Select an option

Save markogresak/6b25a99108a04df02f0b to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
void ls(char const *path) {
DIR* dir = opendir(path);
struct dirent *entry;
if(dir != NULL) {
printf("Listing directory %s:\n", path);
while((entry = readdir(dir)))
puts(entry->d_name);
closedir (dir);
}
else
printf("Path %s isn't a directory!\n", path);
}
int main(int argc, char const *argv[]) {
if(argv[1])
ls(argv[1]);
else
ls("./");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment