关于文件操作fs.stat的遍历参数无效的问题

发布于 6 年前作者 na322865 次浏览最后编辑 6 年前来自 ask

按照手册文档中对fs.stat的recursive参数设置为true时下述语句报错,提示 stats.isDirectory is not a function.

recursive 为 true 时

fs.stat({  path: `${wx.env.USER_DATA_PATH}/testDir`,  recursive: true,  success: res => {    Object.keys(res.stats).forEach(path => {      const stats = res.stats[path]      console.log(path, stats.isDirectory())
    })
  }
})

再测试不加参数时以下语句执行正常。

示例代码

recursive 为 false 时

const fs = wx.getFileSystemManager()
fs.stat({  path: `${wx.env.USER_DATA_PATH}/testDir`,  success: res => {    console.log(res.stats.isDirectory())
  }
})

经测试在正常执行的语中添加recursive参数设置为true时不影响上述语句的正常执行。

感觉该参数未生效,经查开发环境的基础库已调整为2.5.2 仍然不行。

https://developers.weixin.qq.com/miniprogram/dev/api/FileSystemManager.statSync.html

2 回复
gluo
gluo1 楼6 年前

麻烦提供一下出现问题的机型和微信版本,并且给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题