美文网首页
使用xcode9 编译IOS11时 cocos的system函数

使用xcode9 编译IOS11时 cocos的system函数

作者: 甚解_4703 | 来源:发表于2017-09-28 13:44 被阅读0次

更新成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
}

相关文章

网友评论

      本文标题:使用xcode9 编译IOS11时 cocos的system函数

      本文链接:https://www.haomeiwen.com/subject/eewmextx.html