抖音开放平台Logo
控制台

FileSystemManager.readdir
收藏
我的收藏

基础库 1.15.0 开始支持本方法,这是一个异步方法。

读取目录内文件列表。

前提条件
业务背景
使用限制
注意事项
相关教程

语法

FileSystemManager.readdir(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
dirPathstring
要读取的目录路径
1.15.0
successfunction
接口调用成功的回调函数
1.15.0
failfunction
接口调用失败的回调函数
1.15.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.15.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
filesarray
指定目录下的文件名数组
1.15.0
errMsgstring
"FileSystemManager.readdir:ok"
1.15.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"FileSystemManager.readdir:fail" + 详细错误信息
1.15.0

错误码

errNoerrMsg说明最低支持版本
20000readdir:fail dirPath is invalid
dirPath 参数错误
1.99.0
20001readdir:fail param should be xxx, but got xxx
参数校验错误
1.99.0
21101readdir:fail permission denied, readdir {dirPath_value}
是否有操作权限(dirPath 路径不可读)
1.99.0
21102readdir:fail operation not permitted, readdir {dirPath_value}
类型不正确(dirPath 路径不是目录)
1.99.0
21103readdir:fail no such file or directory, readdir {dirPath_value}
目录不存在
1.99.0

代码示例

const fileSystemManager = tt.getFileSystemManager();

const files = fileSystemManager.readdir({
  dirPath: "ttfile://user/",
  success(res) {
    console.log("调用成功", res.files);
  },
  fail(res) {
    console.log("调用失败", res.errMsg);
  },
});