• 读目录


    int IBC_InfoIndb::read_file_from_dir(const char* path,char filename[][256],int max_size
    ,int* file_cnt)
    {
        DIR* dir=NULL;
        struct   dirent*   entry;
        cout<<"read dir :"<<path<<endl;
        dir=opendir(path);
        if(!dir)
        {
            fprintf(stderr,"opendir %s fail!\n",path);
            return -1;
        }
        *file_cnt=0;
        readdir(dir);
        readdir(dir);
        while(entry=readdir(dir))
        {
            if(*file_cnt>max_size-1)
            {
                closedir(dir);
                return 1;
            }
            if(entry->d_name[0]=='~'||strcmp(strrchr(entry->d_name,'.')+1,"err")==0||
                strcmp(strrchr(entry->d_name,'.')+1,"del")==0)
                continue;
            string str(path);
            str=str+"/"+entry->d_name;
            struct stat buf;
            stat(str.c_str(),&buf);
            if(!S_ISREG(buf.st_mode))
                continue;
            strcpy(filename[*file_cnt],entry->d_name);
            *file_cnt=*file_cnt+1;
        }
        closedir(dir);
        return 0;
    }
  • 相关阅读:
    day 23 索引
    day 22 全量更新
    day 21 求贫困户
    day20 函数,同比,和基础
    知识点记录
    day 20试题
    day 16面试题
    day 13拉链数据做存储
    day 13 拉链数据批量处理
    一维,二维,三维数组,vector 初始化
  • 原文地址:https://www.cnblogs.com/hbt19860104/p/2626405.html
Copyright © 2020-2023  润新知