主页


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

比如我要遍历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);
    }

 

 

posted @ 2014-07-12 18:21  百年工作经验  阅读(1821)  评论(0编辑  收藏  举报