Instantly share code, notes, and snippets.

What would you like to do?
Reads the contents of a root directory
This example reads the contents of a root directory.
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
int main() {
DIR *dir;
struct dirent *entry;
if((dir = opendir("/home/adrian")) == NULL) {
perror("opendir() error");
} else {
puts("Contents of root:");
while((entry = readdir(dir)) != NULL )
printf(" %s\n", entry->d_name);
closedir( dir );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment