- API 概览
- 开放能力
- 基础
- 渲染
- 设备
- 文件
- 位置
- 媒体
- 网络
- 游戏转发分享
- 实时语音
- 数据缓存
- 系统
- 广告
- 界面
- 支付
- Worker
FileSystemManager.readdirSync收藏我的收藏
收藏
我的收藏基础库 1.15.0 开始支持本方法,这是一个同步方法。
读取目录内文件列表。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | 无 |
相关教程 | 无 |
语法
FileSystemManager.readdirSync(dirPath)
参数说明
dirPath
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
string | 是 | 要读取的目录路径 | 1.15.0 |
返回值
类型 | 说明 | 最低支持版本 |
---|---|---|
array | 指定目录下的文件名数组,类型为 Array<string> | 1.15.0 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
20000 | readdir:fail dirPath is invalid | dirPath 参数错误 | 1.99.0 |
20001 | readdir:fail param should be xxx, but got xxx | 参数校验错误 | 1.99.0 |
21101 | readdir:fail permission denied, readdir {dirPath_value} | 是否有操作权限(dirPath 路径不可读) | 1.99.0 |
21102 | readdir:fail operation not permitted, readdir {dirPath_value} | 类型不正确(dirPath 路径不是目录) | 1.99.0 |
21103 | readdir: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);
}
该文档是否有帮助?
点击纠错