收藏
回答

我想知道FileSystemManager.readFile的复杂度是什么样的

问题模块 框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
API和组件 小游戏 需求 FileSystemManager 客户端 6.5.3 2.0.0

假如我在第一次读取文件的时候将这些文件路径都存到一个csv下,第二次就从csv中读取这些文件路径,而不是通过

 FileSystemManager.readdirSync

或者

 FileSystemManager.readdir

来再次获取文件路径,效率会不会提高


最后一次编辑于  2018-09-13  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏关注问题回答

1 个回答

  • 七海千秋
    七海千秋
    2018-09-13
    function cleanAllFiles(path, newAssets, finish) {
        fs.readdir({
            dirPath: path,
            success: function (res) {
                var files = res.files;
                (function next(idx) {
                    if (idx < files.length) {
                        var dirPath = path + '/' + files[idx];
                        var stat = fs.statSync(dirPath);
                        if (stat.isDirectory()) {
                            cleanAllFiles(dirPath, newAssets, function () {
                                next(idx + 1);
                            });
                        } else {
                            // remove old assets
                            if (newAssets && newAssets.indexOf(dirPath) !== -1) {
                                next(idx + 1);
                                return;
                            }
                            fs.unlink({
                                filePath: dirPath,
                                success: function () {
                                    cc.log('unlink local file ' + dirPath + ' successfully!');
                                },
                                fail: function (res) {
                                    cc.warn('failed to unlink file(' + dirPath + '): ' + res ? res.errMsg : 'unknown error');
                                },
                                complete: function () {
                                    next(idx + 1);
                                }
                            });
                        }
                    } else {
                        finish && finish();
                    }
     
                })(0);
            },
            fail: function (res) {
                finish && finish();
            },
        });
    }

    比如官方WX-Downloader.js里这个cleanAllFiles,假如我把这个readdir改成从预存的csv中读取,效率能提高吗

    2018-09-13
    赞同 11
    回复