首页 > 代码库 > cocos2d-x3.2下获取文件夹下所有文件名的方法
cocos2d-x3.2下获取文件夹下所有文件名的方法
这里提供一个函数获取文件夹下所有文件名的方法,直接上代码了。
原文地址:http://blog.csdn.net/qqmcy/article/details/36184733
// // VisibleRect.cpp // Test890 // // Created by 杜甲 on 14-4-28. // // std::vector<std::string> VisibleRect::getFilePathAtVec(std::string filePath) { std::vector<std::string> path_vec; const char* path = filePath.c_str(); char *dir = (char*)malloc(filePath.size() + 1); sprintf(dir, path); DIR *dp; struct dirent *entry; struct stat statbuf; int i=0; if((dp=opendir(dir))==NULL) { fprintf(stderr,"cannot open %s",dir); exit(1); } chdir(dir); while((entry=readdir(dp))!=NULL&&i<255) { stat(entry->d_name,&statbuf); if(!S_ISREG(statbuf.st_mode)) continue; path_vec.push_back(StringUtils::format("%s",entry->d_name)); } return path_vec; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。