创建目录
属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| dirPath | string | 是 | 创建的目录路径 (本地路径) | |
| recursive | boolean | false | 否 | 是否递归创建该目录的上级目录。 - 当 dirPath 为a/b/c/d 且recursive 为true 时,会依次创建a →a/b →a/b/c →a/b/c/d |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(无论成功/失败都会执行) |
const fs = xhs.getFileSystemManager()
// 异步接口
fs.mkdir({
dirPath: `${xhs.env.USER_DATA_PATH}/example`,
recursive: false,
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
fs.mkdirSync(`${xhs.env.USER_DATA_PATH}/example`, false)
} catch(e) {
console.error(e)
}