Pages

Thursday, December 6, 2012

How to get the contents of a directory?


#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <assert.h>

int main(int argc, char *argv[])
{
 DIR * dp = opendir(".");
 assert(dp != NULL);

 struct dirent *d;
 while ((d = readdir(dp)) != NULL)
 {
    printf("%d %hd %ld %s\n", (int)d->d_type, d->d_reclen, (long) d->d_ino, d->d_name);
 }
 closedir(dp);
 return 0;
}


No comments:

Post a Comment