FileSystemManager.stat(Object object)

获取文件 Stats 对象

参数

Object object

属性类型默认值必填说明最低版本
pathstring文件/目录路径 (本地路径)
recursivebooleanfalse是否递归获取目录下的每个文件的 Stats 信息2.3.0
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性类型说明
statsStats/Object当 recursive 为 false 时,res.stats 是一个 Stats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个 Object,key 以 path 为根路径的相对路径,value 是该路径对应的 Stats 对象。

object.fail 回调函数

参数
Object res
属性类型说明
errMsgstring错误信息

res.errMsg 的合法值

说明最低版本
fail permission denied, open ${path}指定的 path 路径没有读权限
fail no such file or directory ${path}文件不存在

示例代码

recursive 为 false 时

  1. let fs = wx.getFileSystemManager()
  2. fs.stat({
  3. path: `${wx.env.USER_DATA_PATH}/testDir`,
  4. success: res => {
  5. console.log(res.stats.isDirectory())
  6. }
  7. })

recursive 为 true 时

  1. fs.stat({
  2. path: `${wx.env.USER_DATA_PATH}/testDir`,
  3. recursive: true,
  4. success: res => {
  5. Object.keys(res.stats).forEach(path => {
  6. let stats = res.stats[path]
  7. console.log(path, stats.isDirectory())
  8. })
  9. }
  10. })