# FileSystemManager.accessSync(string path)
以 [Promise 风格]((app-service/api#异步 -API- 返回-Promise)) 调用:不支持
小程序插件:支持,需要小程序基础库版本不低于 2.19.2
相关文档: 文件系统
# 功能描述
FileSystemManager.access 的同步版本
# 参数
# string path
要判断是否存在的文件/目录路径 (本地路径)
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail no such file or directory ${path} | 文件/目录不存在 | |
fail sdcard not mounted | Android sdcard 挂载失败 |
# 示例代码
const fs = wx.getFileSystemManager()
// 判断文件/目录是否存在
fs.access({
path: `${wx.env.USER_DATA_PATH}/hello.txt`,
success(res) {
// 文件存在
console.log(res)
},
fail(res) {
// 文件不存在或其他错误
console.error(res)
}
})
// 同步接口
try {
fs.accessSync(`${wx.env.USER_DATA_PATH}/hello.txt`)
} catch(e) {
console.error(e)
}