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