# FileSystemManager.rmdirSync(string dirPath, boolean recursive)
以 Promise 风格 调用:不支持
小程序插件:支持,需要小程序基础库版本不低于 2.19.2
相关文档: 文件系统
# 功能描述
FileSystemManager.rmdir 的同步版本
# 参数
# string dirPath
要删除的目录路径 (本地路径)
# boolean recursive
基础库 2.3.0 开始支持,低版本需做兼容处理。
是否递归删除目录。如果为 true,则删除该目录和该目录下的所有子目录以及文件。
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail no such file or directory ${dirPath} | 目录不存在 | |
fail directory not empty | 目录不为空 | |
fail permission denied, open ${dirPath} | 指定的 dirPath 路径没有写权限 | |
fail sdcard not mounted | Android sdcard 挂载失败 |
# 示例代码
const fs = wx.getFileSystemManager()
fs.rmdir({
dirPath: `${wx.env.USER_DATA_PATH}/example`,
recursive: false,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
const res = fs.rmdirSync(`${wx.env.USER_DATA_PATH}/example`, false)
console.log(res)
} catch(e) {
console.error(e)
}