opendir, readdir

来源:互联网 发布:淘宝嘉悦海外专营店 编辑:程序博客网 时间:2024/05/01 22:42
#include <stdio.h>#include <sys/types.h>#include <dirent.h>#include <errno.h>#include <string.h>int main(int argc,char *argv[]){    if(argc < 1)    {        printf("./dirent directory");        return -1;    }    DIR *dp;    if((dp = opendir(argv[1])) == NULL)    {        printf("opendir error %s\n",strerror(errno));        return -1;    }    struct dirent * dirp ;    while((dirp = readdir(dp)) != NULL)    {        printf("%s\n",dirp->d_name);    }    return 0;}


0 0