更新成xcode9,发现cocos的FileUtils移除目录使用的是system函数,但是已经无法使用,所以我打算使用stdio.h里面的标准方法remove方法,修改如下:
bool FileUtils::removeDirectory(const std::string& path)
{
#if !defined(CC_TARGET_OS_TVOS)
// std::string command = "rm -r ";
// // Path may include space.
// command += "\"" + path + "\"";
// if (system(command.c_str()) >= 0)
// return true;
// else
// return false;
bool ret = true;
DIR *pDir;
dirent *ent;
char childpath[512] = {0};
pDir = opendir(path.c_str());
if (!pDir)
return ret;
while ((ent = readdir(pDir)) != NULL)
{
if (ent->d_type & DT_DIR)
{
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
sprintf(childpath, "%s/%s", path.c_str(), ent->d_name);
if (!FileUtils::removeDirectory(childpath)){
break;
}
}
else
{
std::string str_file = path + "/" + ent->d_name;
remove(str_file.c_str());
}
}
closedir(pDir);
remove(path.c_str());
return ret;
#else
return false;
#endif
}
网友评论