Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
I'd like to list all files and directories in the assets, but FileUtils#listFiles return files only.
After reading the source code, i found the code of CCFileUtils-android.cpp L340 --- function AAssetDir_getNextFileName will filter directories in the result list.
auto *dir = AAssetManager_openDir(assetmanager, relativePath.c_str());
if(nullptr == dir) {
LOGD("... FileUtilsAndroid::failed to open dir %s", relativePath.c_str());
AAssetDir_close(dir);
return fileList;
}
const char *tmpDir = nullptr;
while((tmpDir = AAssetDir_getNextFileName(dir))!= nullptr)
{
string filepath(tmpDir);
if(isDirectoryExistInternal(filepath)) filepath += "/";
fileList.push_back(filepath);
}
AAssetDir_close(dir);
126 | const char* AAssetDir_getNextFileName(AAssetDir* assetDir)
| 127 | {
| 128 | const char* returnName = NULL;
| 129 | size_t index = assetDir->mCurFileIndex;
| 130 | const size_t max = assetDir->mAssetDir->getFileCount();
| 131 |
| 132 | // Find the next regular file; explicitly don't report directories even if the
| 133 | // underlying implementation changes to report them. At that point we can add
| 134 | // a more general iterator to this native interface set if appropriate.
| 135 | while ((index < max) && (assetDir->mAssetDir->getFileType(index) != kFileTypeRegular)) {
| 136 | index++;
| 137 | }
| 138 |
| 139 | // still in bounds? then the one at 'index' is the next to be reported; generate
| 140 | // the string to return and advance the iterator for next time.
| 141 | if (index < max) {
| 142 | assetDir->mCachedFileName = assetDir->mAssetDir->getFileName(index);
| 143 | returnName = assetDir->mCachedFileName.string();
| 144 | index++;
| 145 | }
| 146 |
| 147 | assetDir->mCurFileIndex = index;
| 148 | return returnName;
| 149 | }
So, is there anyone who can help to fix this problem? thx.
I'd like to list all files and directories in the assets, but FileUtils#listFiles return files only.
After reading the source code, i found the code of
CCFileUtils-android.cpp
L340 --- functionAAssetDir_getNextFileName
will filter directories in the result list.The source code of
AAssetDir_getNextFileName
is asset_manager.cpp.So, is there anyone who can help to fix this problem? thx.