小程序开放平台

文档中心
基础
界面
网络
数据缓存
媒体
位置
开放接口
设备
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.unlinkSync

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

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

功能描述

FileSystemManager.unlink
的同步版本,用于删除指定文件。

参数

参数名
类型
说明
filePathstring要删除的文件路径(本地路径)

示例代码

javascript
const fs = xhs.getFileSystemManager()
fs.unlink({
  filePath: `${xhs.env.USER_DATA_PATH}/hello.txt`,
  success(res) {
    console.log(res)
  },
  fail(res) {
    console.error(res)
  }
})

// 同步接口
try {
  const res = fs.unlinkSync(`${xhs.env.USER_DATA_PATH}/hello.txt`)
  console.log(res)
} catch(e) {
  console.error(e)
}
该文档是否对您有帮助?