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

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

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

  1. //  
  2. //  VisibleRect.cpp  
  3. //  Test890  
  4. //  
  5. //  Created by 杜甲 on 14-4-28.  
  6. //  
  7. //  
  8. std::vector<std::string> VisibleRect::getFilePathAtVec(std::string filePath)  
  9. {  
  10.     std::vector<std::string> path_vec;  
  11.       
  12.      
  13.     const char* path = filePath.c_str();  
  14.       
  15.   
  16.       
  17.     char *dir = (char*)malloc(filePath.size() + 1);  
  18.       
  19.     sprintf(dir,  path);  
  20.       
  21.       
  22.       
  23.     DIR *dp;  
  24.     struct dirent *entry;  
  25.     struct stat statbuf;  
  26.     int i=0;  
  27.      
  28.     if((dp=opendir(dir))==NULL)  
  29.     {  
  30.         fprintf(stderr,"cannot open %s",dir);  
  31.         exit(1);  
  32.     }  
  33.     chdir(dir);  
  34.       
  35.     while((entry=readdir(dp))!=NULL&&i<255)  
  36.     {  
  37.         stat(entry->d_name,&statbuf);  
  38.         if(!S_ISREG(statbuf.st_mode))  
  39.             continue;  
  40.         path_vec.push_back(StringUtils::format("%s",entry->d_name));  
  41.     }  
  42.     return path_vec;  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值