Skip to content

Instantly share code, notes, and snippets.

@thinkphp thinkphp/opendir.c
Created Oct 31, 2018

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
You can’t perform that action at this time.