tt.removeSavedFile
收藏
我的收藏

基础库 1.15.0 开始支持本方法,这是一个异步方法。

删除该小程序下用户目录内的文件,用户目录以 ttfile://user 开头。

前提条件
业务背景
使用限制
注意事项
支持沙盒
相关教程

语法

tt.removeSavedFile(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
filePathstring
要删除的文件路径
1.15.0
successfunction
接口调用成功的回调函数
1.15.0
failfunction
接口调用失败的回调函数
1.15.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.15.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
removeSavedFile:ok
1.15.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
格式为 removeSavedFile:fail + 错误信息
1.15.0

错误码

errNoerrMsg说明最低支持版本
20000removeSavedFile:fail filePath is invalid
filePath 参数错误
1.15.0
21101removeSavedFile:fail permission denied, removeSavedFile %s
路径不可写
1.99.0
21102removeSavedFile:fail no such file or directory, removeSavedFile %s
文件不存在
1.99.0
21104removeSavedFile:fail operation not permitted, removeSavedFile %s
filePath 类型不是文件
1.99.0

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

tt.getSavedFileList({
  success(res) {
    console.log("当前用户目录下的文件:", res.fileList)
    removeSavedFile(res.fileList)
  },
})

function removeSavedFile(fileList) {
  fileList.forEach((filePath) => {
    tt.removeSavedFile({
      filePath,
      success(res) {
        console.log(`${filePath} 删除成功`)
      },
      fail(res) {
        console.error(`${filePath} 删除失败`, res.errMsg)
      },
    })
  })
}