抖音开放平台Logo
控制台

FileSystemManager.readdirSync
收藏
我的收藏

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

读取目录内文件列表。

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

语法

FileSystemManager.readdirSync(dirPath)

参数说明

dirPath

类型默认值必填说明最低支持版本
string
要读取的目录路径
1.15.0

返回值

类型说明最低支持版本
array

指定目录下的文件名数组,类型为 Array<string>

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();

try {
  const files = fileSystemManager.readdirSync("ttfile://user/");
  console.log("调用成功", files);
} catch (err) {
  console.log("调用失败", err);
}