首页 > 其他 > 详细

Cocos2dx 遍历 文件夹下所有的文件(草稿)

时间:2017-06-06 15:31:02      阅读:591      评论:0      收藏:0      [点我收藏+]

备份,怕忘了

static std::vector<string> getFilePathAtVec(string folderPath, int depth)
{
       std::vector<string> path_vec;
        DIR *dp;
        struct dirent *entry;
        struct stat statbuf;
        if((dp = opendir(folderPath.c_str())) == NULL) {
            fprintf(stderr,"cannot open directory: %s\n", folderPath.c_str());
            return path_vec;
        }
        chdir(folderPath.c_str());
        while((entry = readdir(dp)) != NULL) {
            lstat(entry->d_name,&statbuf);
            if(S_ISDIR(statbuf.st_mode)) {
                
                if(strcmp(".",entry->d_name) == 0 ||
                   strcmp("..",entry->d_name) == 0)
                    continue;
                printf("%*s%s/\n",depth,"",entry->d_name);
                getFilePathAtVec(entry->d_name,depth+4);
            } else {
                string filename = entry->d_name;
                path_vec.push_back(filename);
            }
        }
        chdir("..");
        closedir(dp);
    return path_vec;
}

 

Cocos2dx 遍历 文件夹下所有的文件(草稿)

原文:http://www.cnblogs.com/zhangfeitao/p/6951598.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!