cocos2d-x遍历zip某个目录(可用于android中apk包的文件访问)

利用cocos2d-x里封装的unZip进行遍历文件,取出每一个文件

 1 vector<string> ToolUtils::getFiles( const char* zipFile, const char* floder )
 2 {
 3     vector<string> files;
 4     unsigned char * pBuffer = NULL;
 5     unzFile pFile = NULL;
 6     string rejustFloder(floder);
    //floder必须以/结尾
7 if(rejustFloder.find_last_not_of("/")) { 8 rejustFloder = rejustFloder + "/"; 9 floder = rejustFloder.c_str(); 10 } 11 do 12 { 13 CC_BREAK_IF(!zipFile || !floder); 14 CC_BREAK_IF(strlen(zipFile) == 0); 15 16 pFile = unzOpen(zipFile); 17 CC_BREAK_IF(!pFile); 18 19 int nRet = unzLocateFile(pFile, floder, 1); 20 CC_BREAK_IF(UNZ_OK != nRet); 21 22 while (unzGoToNextFile(pFile) == UNZ_OK) 23 { 24 char szFilePathA[260]; 25 unz_file_info FileInfo; 26 nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0); 27 CC_BREAK_IF(UNZ_OK != nRet); 28 string path(szFilePathA); //最后一个为/为目录过滤掉,且开头必须以文件开头 29 if(path[path.size() - 1] != '/' && path.find(floder) == 0) { 30 files.insert(files.begin(), string(szFilePathA)); 31 } 32 } 33 } while (0); 34 35 if (pFile) 36 { 37 unzClose(pFile); 38 } 39 40 return files; 41 }

这样我们zipFile就是某一个zip,在android平台上的就是getApkPath(),floder就是取zip里的相对路径。

 

转载于:https://www.cnblogs.com/tickdream/archive/2013/05/25/3099430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值