我将文件保存在iPhone模拟器的可写目录中。 可以在运行时动态删除和创建文件。 我想使用目录路径而不是文件名列出特定目录中的这些文件。
示例:
/Users/mine/Library/Application Support/iPhone Simulator/7.1/Applications/022F7891-1983-4791-AB59-451B2EAF4FB8/Documents/stage/stage_1.json
/Users/mine/Library/Application Support/iPhone Simulator/7.1/Applications/022F7891-1983-4791-AB59-451B2EAF4FB8/Documents/stage/stage_2.json
/Users/mine/Library/Application Support/iPhone Simulator/7.1/Applications/022F7891-1983-4791-AB59-451B2EAF4FB8/Documents/stage/stage_24.json
/Users/mine/Library/Application Support/iPhone Simulator/7.1/Applications/022F7891-1983-4791-AB59-451B2EAF4FB8/Documents/stage/stage_3.json
/Users/mine/Library/Application Support/iPhone Simulator/7.1/Applications/022F7891-1983-4791-AB59-451B2EAF4FB8/Documents/stage/stage_4.bmp
vector = getFilesInDir(FileUtils :: getInstance() - > getWritablePath()+ string(" Documents / stage")," json");
vector => (" stage_1.json"," stage_1.json"," stage_1.json"," stage_1.json")
答案 0 :(得分:2)
cocos2dx中没有用于列出目录内容的跨平台API。您可以在创建文件名时将其存储在数组中。
如果您只想按名称阅读文件,则需要在CCFileUtils
FileUtils *fileUtils = FileUtils::getInstance();
vector<string> searchPaths = fileUtils->getSearchPaths();
string path = fileUtils->getWritablePath() + "stage";
searchPaths.insert(searchPaths.begin(), path);
fileUtils->setSearchPaths(searchPaths);