FileSystemManager.readdirSync
收藏
我的收藏

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

读取目录内文件列表。

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

语法

FileSystemManager.readdirSync(dirPath)

参数说明

dirPath

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

返回值

类型说明最低支持版本
array
返回值为指定目录下的文件名数组, 类型为 string[]
1.15.0

错误码

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

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

const fileSystemManager = tt.getFileSystemManager()

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