zoukankan      html  css  js  c++  java
  • 读目录

    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;
    }
  • 相关阅读:
    pyinstaller guid
    python filter()和map()函数
    python eval()
    day6
    repr()函数是什么鬼?
    fibonacci_question
    冒泡算法
    python 函数
    day4作业
    NOIp 2013 #1 积木大赛 Label:有趣的模拟
  • 原文地址:https://www.cnblogs.com/hbt19860104/p/2626405.html
Copyright © 2011-2022 走看看