- API 概览
- 开放能力
- 基础
- 渲染
- 设备
- 文件
- 位置
- 媒体
- 网络
- 游戏转发分享
- 实时语音
- 数据缓存
- 系统
- 广告
- 界面
- 支付
- Worker
FileSystemManager.rmdir收藏我的收藏
收藏
我的收藏基础库 1.15.0 开始支持本方法,这是一个异步方法。
删除目录, 只能是 ttfile://user 下的目录。
前提条件 | 无 |
业务背 景 | 无 |
使用限制 | 无 |
注意事项 | 开发者只能删除 ttfile://user 下的目录。 |
相关教程 | 无 |
语法
FileSystemManager.rmdir(options)
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
recursive | boolean | 否 | 是否递归删除目录下的文件,false 的情况下只能删除空目录 | 1.15.0 | |
dirPath | string | 是 | 要删除的目录路径, 必须以 ttfile://user 开头 | 1.15.0 | |
success | function | 否 | 接口调用成功的回调函数 | 1.15.0 | |
fail | function | 否 | 接口调用失败的回调函数 | 1.15.0 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 1.15.0 |
回调成功
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "FileSystemManager.rmdir:ok" | 1.15.0 |
回调失败
object 类型,属性如下:
属性名 | 类型 | 说明 | 最低支持版本 |
---|---|---|---|
errMsg | string | "FileSystemManager.rmdir:fail" + 详细错误信息 | 1.15.0 |
错误码
errNo | errMsg | 说明 | 最低支持版本 |
---|---|---|---|
20000 | rmdir:fail dirPath is invalid | dirPath 参数错误 | 1.99.0 |
20001 | rmdir:fail param should be xxx, but got xxx | 参数校验 错误 | 1.99.0 |
21101 | rmdir:fail permission denied, rmdir {dirPath_value} | dirPath 路径不可写 | 1.99.0 |
21102 | rmdir:fail no such file or directory, rmdir {dirPath_value} | dirPath 路径不存在 | 1.99.0 |
21103 | rmdir:fail directory not empty | 目录不为空,且 recursive 为 false | 1.99.0 |
21105 | rmdir:fail operation not permitted, rmdir {dirPath_value} | 类型不正确(不是目录) | 1.99.0 |
代码示例
const fileSystemManager = tt.getFileSystemManager();
// 先创建一个目录
const examplePath = "ttfile://user/example-dir";
try {
fileSystemManager.mkdirSync(examplePath);
console.log("创建成功");
} catch (err) {
console.log("创建失败", err);
}
// 删除文件
fileSystemManager.rmdir({
dirPath: examplePath,
success(_res) {
console.log("创建成功");
},
fail(res) {
console.log("创建失败", res.errMsg);
},
});
该文档是否有帮助?
点击纠错