抖音开放平台Logo
控制台

FileSystemManager.rmdirSync
收藏
我的收藏

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

删除目录,开发者只能删除 用户目录(ttfile://user) 下的目录。

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

语法

FileSystemManager.rmdirSync(dirPath, recursive)

参数说明

dirPath

类型默认值必填说明最低支持版本
string
要删除的目录路径, 必须以 ttfile://user 开头的字符串
1.15.0

recursive

类型默认值必填说明最低支持版本
boolean
是否递归删除目录下的文件
1.15.0

返回值

错误码

errNoerrMsg说明最低支持版本
20000rmdirSync:fail dirPath is invalid
dirPath 参数错误
1.99.0
20001rmdirSync:fail param should be xxx, but got xxx
参数校验错误
1.99.0
21101rmdirSync:fail permission denied, rmdirSync {dirPath_value}
dirPath 路径不可写
1.99.0
21102rmdirSync:fail no such file or directory, rmdirSync {dirPath_value}
dirPath 路径不存在
1.99.0
21103rmdirSync:fail directory not empty
目录不为空,且 recursive 为 false
1.99.0
21105rmdirSync:fail operation not permitted, rmdirSync {dirPath_value}
类型不正确(不是目录)
1.99.0

代码示例

const fileSystemManager = tt.getFileSystemManager();
// 必须以 "ttfile://user" 开头
const exmaplePath = "ttfile://user/example-dir";
try {
  fileSystemManager.mkdirSync(exmaplePath);
  console.log("成功");
} catch (err) {
  console.log("失败", err);
}
try {
  fileSystemManager.rmdirSync(exmaplePath);
  console.log("成功");
} catch (err) {
  console.log("失败", err);
}