# FileSystemManager.readdir(Object object)

异步读取指定目录中的文件列表(仅当前层级,不递归)。

# 支持情况

项 说明
兼容性 兼容微信

# 语法

const fs = mt.getFileSystemManager()
fs.readdir({ dirPath, success, fail, complete })

# 参数

Object object

属性 类型 默认值 必填 说明
dirPath string — 是 要读取的目录路径
success function — 否 成功回调
fail function — 否 失败回调
complete function — 否 完成回调(成功或失败均触发)

success 回调参数

属性 类型 说明
files string[] 目录中的文件名数组(不含路径,仅文件名)

# 返回值

无返回值。

# 示例代码

const fs = mt.getFileSystemManager()
fs.readdir({
  dirPath: `${mt.env.USER_DATA_PATH}`,
  success(res) {
    console.log(res.files)
  },
  fail(err) {
    console.error(err.errMsg)
  }
})

# 与微信差异

无差异(行为与微信小游戏一致)。

上次更新: 8/10/2026, 5:36:37 PM