当前位置:网站首页>cocos2d-x implements cross-platform directory traversal
cocos2d-x implements cross-platform directory traversal
2022-07-31 06:03:00 【xuyid】
#include
#else
#include
#include
#include
#include
#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{
// Determine if there are subdirectories
if (FileInfo.attrib & _A_SUBDIR)
{
//This statement is very important
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;
_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);
54 }
}
chdir("..");
closedir(dp);
#endif
}
边栏推荐
- Filter out egrep itself when using ps | egrep
- cocoscreator 显示刘海内容
- Navicat从本地文件中导入sql文件
- sqlite 查看表结构 android.database.sqlite.SQLiteException: table splitTable has no column named
- MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案
- [Cloud native] Simple introduction and use of microservice Nacos
- 为什么bash中的read要配合while才能读取/dev/stdin的内容
- jenkins +miniprogram-ci upload WeChat applet with one click
- TransactionTemplate 事务编程式写法
- Tencent Cloud Lightweight Server deletes all firewall rules
猜你喜欢
随机推荐
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
2021美赛C题M奖思路
How MySQL - depots table?A look at will understand
Hyper-V新建虚拟机注意事项
js中的break与continue退出
VS connects to MYSQL through ODBC (1)
js中流程控制语句
js中的对象与函数的理解
[windows]--- SQL Server 2008 super detailed installation tutorial
腾讯云轻量服务器删除所有防火墙规则
What is the difference between NFT and digital collection?
Flutter mixed development module dependencies
Pure shell implementation of text replacement
After unicloud is released, the applet prompts that the connection to the local debugging service failed. Please check whether the client and the host are under the same local area network.
场效应管 | N-mos内部结构详解
Using IIS10 to build an asp website in win11
Global scope and function scope in js
This in js points to the prototype object
理解js运算符
podspec 校验依赖出错问题 pod lib lint ,需要指定源