码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-07-01 15:38:59      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:cocos2d-x   c++   文件名   路径   

这里提供一个函数获取文件夹下所有文件名的方法,直接上代码了。

原文地址: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;
}


cocos2d-x3.2下获取文件夹下所有文件名的方法,布布扣,bubuko.com

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

标签:cocos2d-x   c++   文件名   路径   

原文地址:http://blog.csdn.net/qqmcy/article/details/36184733

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!