# FileSystemManager.readdirSync(string dirPath)
同步读取指定目录中的文件列表(仅当前层级,不递归)。
# 支持情况
| 项 | 说明 |
|---|---|
| 兼容性 | 兼容微信 |
# 语法
const fs = mt.getFileSystemManager()
const files = fs.readdirSync(dirPath)
# 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dirPath | string | 是 | 要读取的目录路径 |
# 返回值
string[] — 目录中的文件名数组(不含路径,仅文件名);失败时返回错误信息字符串。
# 示例代码
const fs = mt.getFileSystemManager()
const files = fs.readdirSync(`${mt.env.USER_DATA_PATH}`)
console.log(files)
# 与微信差异
无差异(行为与微信小游戏一致)。