关于文件操作fs.stat的遍历参数无效的问题
发布于 4 年前 作者 na32 2553 次浏览 来自 问答

按照手册文档中对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

回到顶部