打开目录、读取目录里面的内容 opendir readdir

来源:互联网 发布:金蝶软件优缺点 编辑:程序博客网 时间:2024/06/01 10:47
#include<stdio.h>#include <dirent.h>#include<stdlib.h>//打开目录//读取目录里面的内容//DIR *opendir(const char *name);//struct dirent *readdir(DIR *dirp);#if 0struct dirent {               ino_t          d_ino;       /* inode number */               off_t          d_off;       /* offset to the next dirent */               unsigned short d_reclen;    /* length of this record */               unsigned char  d_type;      /* type of file; not supported                                              by all file system types */               char           d_name[256]; /* filename 需要*/           };#endifint main(int argc,char *argv[]){    DIR *dp;    dp = opendir(argv[1]);    if(dp == NULL)    {        perror("opendir failed");        exit(1);    }    struct dirent *dir;    while((dir = readdir(dp)) != NULL) //!=    {        printf("%s\n",dir->d_name);    }    return 0;}/*$ ./a.out test...test1test1.ctest2test2.c*/
阅读全文
0 0
原创粉丝点击