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

cocos2d-x3.2下获取文件夹下所有文件名的方法

2014-07-01 13:38 323 查看
这里提供一个函数获取文件夹下所有文件名的方法,直接上代码了。

原文地址:/article/1640629.html

//
//  VisibleRect.cpp
//  Test890
//
//  Created by 杜甲 on 14-4-28.
//
//
std::vector<std::string> VisibleRect::getFilePathAtVec(std::string filePath)
{
    std::vector<std::string> path_vec;
    DIR *dp;
    struct dirent *entry;
    struct stat statbuf;
    int i=0;
   
    if((dp=opendir(filePath.c_str()))==NULL)
    {
        fprintf(stderr,"cannot open %s",filePath.c_str());
        exit(1);
    }
    chdir(filePath.c_str());
    
    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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: