FileSystemManager.unlinkSync
收藏我的收藏
基础库 1.15.0 开始支持本方法,这是一个同步方法。
删除文件,只能删除 用户目录(ttfile://user)下的文件。
前提条件 | 无 |
业务背景 | 无 |
使用限制 | 无 |
注意事项 | filePath 必须以 ttfile://user 开头 |
相关教程 | 无 |
语法
FileSystemManager.unlinkSync(filePath)
参数说明
filePath
类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|
string | 是 | 要删除的文件路径,必须以 ttfile://user 开头。 | 1.15.0 |
返回值
无
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
20001 | invalid param | 参数错误 | 1.15.0 |
10401 | error stack | 小游戏框架内部错误,有需要请创建工单咨询 | 1.15.0 |
21101 | permission denied, $apiName $dirPath | 1.15.0 | |
21102 | no such file or directory, $apiName $dirPath | 1.15.0 | |
21103 | operation not permitted, $apiName $filePath | 1.15.0 | |
20000 | params $paramName is required | 1.15.0 | |
20000 | params $paramName type is not $paramType type | 1.15.0 | |
20000 | $paramName is invalid | 1.15.0 | |
21104 | 错误码为系统返回 | 小游戏框架内部错误,有需要请创建工单咨询 | 1.15.0 |
20000 | internal error | 小游戏框架内部错误,有需要请创建工单咨询 | 1.15.0 |
代码示例
const fileSystemManager = tt.getFileSystemManager(); tt.chooseImage({ success(res) { // 保存临时文件到 用户目录 const savedFilePath = fileSystemManager.saveFileSync(res.tempFilePaths[0]); try { // 删除文件 fileSystemManager.unlinkSync(savedFilePath); console.log("删除成功"); } catch (err) { console.log("删除失败", err); } }, });