# Array.<string> FileSystemManager.readdirSync(string dirPath)
以 Promise 风格 调用:不支持
相关文档: 文件系统
# 功能描述
FileSystemManager.readdir 的同步版本
# 参数
# string dirPath
要读取的目录路径 (本地路径)
# 返回值
# Array.<string> files
指定目录下的文件名数组。
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail no such file or directory ${dirPath} | 目录不存在 | |
fail not a directory ${dirPath} | dirPath 不是目录 | |
fail permission denied, open ${dirPath} | 指定的 filePath 路径没有读权限 | |
fail sdcard not mounted | Android sdcard 挂载失败 |
# 注意事项
- readdir接口无法访问文件系统根路径(wxfile://)。
示例代码
const fs = wx.getFileSystemManager()
fs.readdir({
dirPath: `${wx.env.USER_DATA_PATH}/example`,
success(res) {
console.log(res.files)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)
console.log(res)
} catch(e) {
console.error(e)
}