首页 > 代码库 > c代码读取目录信息

c代码读取目录信息

#include <stdio.h>#include <sys/types.h>#include <dirent.h>int main(void) {    DIR *dp;    struct dirent *ep;    dp = opendir ("./");    if (dp != NULL) {        while ((ep = readdir (dp)) != NULL) {            printf("%s %d\n", ep->d_name, ep->d_type);        }        (void) closedir (dp);    } else {        perror ("Couldn‘t open the directory");    }    return 0;}

 

c代码读取目录信息