FileSystemManager.rmdir
收藏
我的收藏

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

删除目录, 只能是 `ttfile://user` 下的目录。

前提条件
业务背景
使用限制
注意事项
开发者只能删除 ttfile://user 下的目录。
支持沙盒
相关教程

语法

FileSystemManager.rmdir(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
recursivebooleanfalse
是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
1.81.0
dirPathstring
要删除的目录路径, 必须以 `ttfile://user` 开头
1.15.0
successfunction
接口调用成功的回调函数
1.15.0
failfunction
接口调用失败的回调函数
1.15.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.15.0

回调成功

object 类型,属性如下:

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

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"rmdir:fail " + 详细错误信息
1.15.0

错误码

errNoerrMsg说明最低支持版本
20000rmdir:fail dirPath is invalid
dirPath 参数错误
1.99.0
21101rmdir:fail permission denied, rmdir %s
dirPath 路径不可写
1.99.0
21102rmdir:fail no such file or directory, rmdir %s
dirPath 路径不存在
1.99.0
21103rmdir:fail directory not empty
目录不为空,且 recursive 为 false
1.99.0
21105rmdir:fail operation not permitted, rmdir %s
类型不正确(不是目录)
1.99.0

扫码体验

请使用字节宿主APP扫码

代码示例

开发者工具中预览

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,
  recursive: false,
  success(_res) {
    console.log("创建成功")
  },
  fail(res) {
    console.log("创建失败", res.errMsg)
  },
})