当前位置:网站首页>cocos2d-x 实现跨平台的目录遍历
cocos2d-x 实现跨平台的目录遍历
2022-07-31 05:15:00 【xuyid】
#include <io.h>
#else
#include <unistd.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#endif
void dfsFolder(string folderPath, int depth = 0);
void dfsFolder( string folderPath, int depth)
{
#ifdef WIN32
_finddata_t FileInfo;
string strfind = folderPath + "\\*";
long Handle = _findfirst(strfind.c_str(), &FileInfo);
if (Handle == -1L)
{
cerr << "can not match the folder path" << endl;
exit(-1);
}
do{
//判断是否有子目录
if (FileInfo.attrib & _A_SUBDIR)
{
//这个语句很重要
if( (strcmp(FileInfo.name,".") != 0 ) &&(strcmp(FileInfo.name,"..") != 0))
{
string newPath = folderPath + "\\" + FileInfo.name;
dfsFolder(newPath);
}
}
else
{
string filename = (folderPath + "\\" + FileInfo.name);
28 cout << folderPath << "\\" << FileInfo.name << " " << endl;
}
}while (_findnext(Handle, &FileInfo) == 0);
_findclose(Handle);
#else
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if((dp = opendir(folderPath.c_str())) == NULL) {
fprintf(stderr,"cannot open directory: %s\n", folderPath.c_str());
return;
}
chdir(folderPath.c_str());
while((entry = readdir(dp)) != NULL) {
lstat(entry->d_name,&statbuf);
if(S_ISDIR(statbuf.st_mode)) {
if(strcmp(".",entry->d_name) == 0 ||
strcmp("..",entry->d_name) == 0)
continue;
printf("%*s%s/\n",depth,"",entry->d_name);
dfsFolder(entry->d_name,depth+4);
} else {
string filename = entry->d_name;
54 printf("%*s%s\n",depth,"",entry->d_name);
}
}
chdir("..");
closedir(dp);
#endif
}
边栏推荐
- [Elastic-Job] Overview of Distributed Scheduling Tasks
- What is an EVM Compatible Chain?
- leetcode-每日一题745. 前缀和后缀搜索(哈希和字典树)
- [JVM Loading]---Class Loading Mechanism
- Judgment of database in SQL injection
- Three-party login using wallet Metamask based on web3.0
- js中的this指向与原型对象
- 著名网站msdn.itellyou.cn原理分析
- [swagger close] The production environment closes the swagger method
- Linux中mysql密码修改方法(亲测可用)
猜你喜欢
随机推荐
Powershell中UTF-8环境中文乱码解决办法
(Crypto必备干货)详细分析目前NFT的几大交易市场
[windows]--- SQL Server 2008 super detailed installation tutorial
SQL注入中数据库的判断
What is GameFi?
DeFi 项目中的治理Token
gin框架学习-Gin框架和Gorm框架搭建一个简单的API微服务
为什么redis是单线程还那么快?
Judgment of database in SQL injection
leetcode-每日一题745. 前缀和后缀搜索(哈希和字典树)
js中的break与continue退出
了解SSRF,这一篇就足够了
sqlmap注入教程 常用指令
05 【绑定样式 条件渲染 列表渲染】
阿里云中mysql数据库被攻击了,最终数据找回来了
What is an EVM Compatible Chain?
For penetration testing methods where the output point is a timestamp (take Oracle database as an example)
C language tutorial (1) - preparation
MySQL高级学习笔记
Regular Expression Basics

![[Elastic-Job source code analysis] - job listener](/img/99/5e047b1aa83aad7d7f17b4eec606e6.png)







