FileSystemManager.stat(Object object)
获取文件 Stats 对象
参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 | 
|---|---|---|---|---|---|
| path | string | 是 | 文件/目录路径 | ||
| recursive | boolean | false | 否 | 是否递归获取目录下的每个文件的 Stats 信息 | |
| success | function | 否 | 接口调用成功的回调函数 | ||
| fail | function | 否 | 接口调用失败的回调函数 | ||
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
object.success 回调函数
参数
Object res
| 属性 | 类型 | 说明 | 
|---|---|---|
| stats | Object | 当 recursive 为 false 时,res.stats 是一个 FileStats 对象。当 recursive 为 true 且 path 是一个目录的路径时,res.stats 是一个普通对象结构,key 以 path 为根路径的相对路径,value 是该路径对应的 FileStats 对象。 | 
FileStats 结构如下:
FileStats {
  lastAccessedTime: 1500000000.0000000,
  lastModifiedTiem: 1500000000.0000000,
  mode: "500",
  size: 196,
  ...
}
object.fail 回调函数
参数
Object res
| 属性 | 类型 | 说明 | 
|---|---|---|
| errMsg | string | 错误信息 | 
res.errMsg 的合法值
| 值 | 说明 | 
|---|---|
| fail permission denied, open [path] | 指定的 path 路径没有读权限 | 
| fail no such file or directory [path] | 文件不存在 | 
示例代码
recursive 为 false 时
const fs = bl.getFileSystemManager()
fs.stat({
  path: `${bl.env.USER_DATA_PATH}/testDir`,
  success: res => {
    console.log(res.stats.isDirectory())
  }
})
recursive 为 true 时
const fs = bl.getFileSystemManager()
fs.stat({
  path: `${bl.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())
    })
  }
})