cocos2d-x 实现目录的遍历 和 文件的全拷贝
来源:互联网 发布:哪的java培训学校好 编辑:程序博客网 时间:2024/05/29 02:13
#include <unistd.h>#include <stdio.h>#include <dirent.h>#include <sys/stat.h>bool mycopyfileios(string src,string dst){ FILE* fp1 =fopen(src.c_str(),"rb"); if (!fp1) { returnfalse; } FILE* fp2 =fopen(dst.c_str(),"wb"); if (!fp2) { fclose(fp1); returnfalse; } char txt[1000]; while (1) { int size =fread(txt, sizeof(char), 1000, fp1); if (size > 0) { int realsize =fwrite(txt, sizeof(char), size, fp2); if (size != realsize) { fclose(fp1); fclose(fp2); returnfalse; } } else { break; } } fclose(fp1); fclose(fp2); returntrue;}//注: string g_dstPath为目标目录 folderPath 为原目录void blAndcpFolder( string folderPath, int depth){ 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); char buf1[1024] = ""; getcwd(buf1, 1024); //切换到目标目录下 if (chdir(g_dstPath.c_str()) != 0) { printf("+++切换目录失败:%s\n", g_dstPath.c_str()); } g_dstPath = g_dstPath + "/" + entry->d_name ;//更新目标目录 char buf2[1024] = ""; char* p1 = NULL; if ((p1 = strstr(g_dstPath.c_str(),"LOLI"))) { strcpy(buf2, p1); } //buf2 是相对路径 WorkAbsolutePath::CreateDirect(buf2);//创建目标目录 // 创建目录--> CCFileUtils::sharedFileUtils()->createFolder(dir); //printf("--创建目录:%s\n", buf2); //切回原目录下 if (chdir(buf1) != 0) { printf("+---+切换目录失败%s", buf1); } blAndcpFolder(entry->d_name,depth+4); } else { string filename = entry->d_name; printf("%*s%s\n",depth,"",entry->d_name); m_curFileNum++; //setProgress(m_curFileNum*100/m_totalFileNum); char buf3[1024] = ""; getcwd(buf3, 1024); char buf4[1024] = ""; sprintf(buf4, "%s/%s", buf3, entry->d_name); string src = buf4; string dst = g_dstPath + "/" + entry->d_name; mycopyfileios(src, dst); } } chdir(".."); closedir(dp); //回到上一级目录 char buf5[1024] = "", buf6[1024] = ""; getcwd(buf5, 1024); if (chdir(g_dstPath.c_str()) != 0) { printf("--------下面一部分切换失败--------\n"); } else{ chdir(".."); getcwd(buf6, 1024); g_dstPath = buf6; chdir(buf5); }}
0 0
- cocos2d-x 实现目录的遍历 和 文件的全拷贝
- cocos2d-x 实现跨平台的目录遍历
- cocos2d-x 实现跨平台的目录遍历
- cocos2d-x 实现跨平台的目录遍历
- [cocos2d-x] -- 避免文件和文件夹的拷贝
- 【Cocos2d-x】cocos2d-x的拷贝机制
- Cocos2d-x的体系结构和目录结构
- 遍历目录下所有各级子目录文件的全路径
- Java实现文件目录的遍历
- cocos2d-x的目录结构
- Cocos2d-x 中 Android.mk 自动添加源文件和头文件目录的路径
- 遍历所有文件和目录的函数
- 遍历目录下的文件和文件夹
- 目录下的文件拷贝,或者整个目录拷贝的实现
- 【存储】Cocos2d-x将资源目录(Assets)文件拷贝到可写目录
- 遍历整个目录树的文件和目录
- 遍历某一指定目录下的文件和目录
- 文件拷贝的实现
- OllyDbg捕捉MFC程序按钮事件
- 提高关键词排名的28个SEO技巧
- NBUT 1217 Dinner
- input标签在谷歌浏览器记住密码下的一个自动填充BUG
- 善用GitHub大有助于学习开发
- cocos2d-x 实现目录的遍历 和 文件的全拷贝
- 使用Python连接postgresql数据库
- ie appendChild 意外地调用了方法或属性访问
- 连接数据库的工具类,以及相关用法
- [林轩田]15-验证法
- [Widget]GradientTabStrip-微信式底部渐变栏
- UVa1586
- git 用法小结1
- Mac ssh远程登陆