您的位置:首页 > 移动开发 > Cocos引擎

cocos2d-x 如何读取遍历文件夹下的所有文件

2014-07-12 18:21 1461 查看
比如我要遍历Resources/music下面所有的文件

导入头文件

#include <sys/stat.h>
#include "dirent.h"
#include "unistd.h"


实现代码

std::string filePath = FileUtils::getInstance()->fullPathForFilename("music");
CCLOG("%s",filePath.c_str());

DIR *dp;
struct dirent *entry;
struct stat statbuf;

dp=opendir(filePath.c_str());
chdir(filePath.c_str());
while((entry=readdir(dp))!=NULL)
{
stat(entry->d_name,&statbuf);
if(!S_ISREG(statbuf.st_mode))
continue;

CCLOG("%s",entry->d_name);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: