小程序开放平台

文档中心
基础
界面
网络
数据缓存
媒体
位置
开放接口
设备
XHSML
性能
文件
removeSavedFile
openDocument
getFileSystemManager
FileSystemManager
FileSystemManager
access
accessSync
appendFile
appendFileSync
copyFile
copyFileSync
getSavedFileList
getFileInfo
mkdir
mkdirSync
readdir
mkdirSync
readdir
readdirSync
rmdir
rmdirSync
rename
renameSync
readFile
readFileSync
removeSavedFile
stat
statSync
saveFile
saveFileSync
truncate
truncateSync
unlink
unlinkSync
unzip
writeFile
writeFileSync
Stats
FileStats
数据分析
画布

fs.accessSync

开发
>
JS API
>
文件
>
FileSystemManager
>
accessSync
>
更新时间:2025-07-23 11:41:41

📌 从基础库 3.125.4 版本开始支持

功能描述

FileSystemManager.access
的同步版本,用于判断文件/目录是否存在。

参数

名称
类型
说明
pathstring要判断是否存在的文件/目录路径(本地路径)

示例代码

javascript
const fs = xhs.getFileSystemManager();

// 同步判断文件/目录是否存在
try {
  fs.accessSync(`${xhs.env.USER_DATA_PATH}/hello.txt`);
  console.log("文件存在");
} catch(e) {
  console.error("错误信息:", e.errMsg);
}
该文档是否对您有帮助?