# FileSystemManager.mkdirSync(string dirPath, boolean recursive)
以 Promise 风格 调用:不支持
小程序插件:支持,需要小程序基础库版本不低于 2.19.2
相关文档: 文件系统
# 功能描述
FileSystemManager.mkdir 的同步版本
# 参数
# string dirPath
创建的目录路径 (本地路径)
# boolean recursive
基础库 2.3.0 开始支持,低版本需做兼容处理。
是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。
# 错误
错误码 | 错误信息 | 说明 |
---|---|---|
fail no such file or directory ${dirPath} | 上级目录不存在(该错误仅在 recursive = false 时生效) | |
fail permission denied, open ${dirPath} | 指定的 filePath 路径没有写权限 | |
fail file already exists ${dirPath} | 有同名文件或目录(该错误仅在 recursive = false 时生效) | |
fail sdcard not mounted | Android sdcard 挂载失败 |
# 示例代码
const fs = wx.getFileSystemManager()
fs.mkdir({
dirPath: `${wx.env.USER_DATA_PATH}/example`,
recursive: false
success(res) {
console.log(res)
},
fail(res) {
console.error(res)
}
})
// 同步接口
try {
fs.mkdirSync(`${wx.env.USER_DATA_PATH}/example`, false)
} catch(e) {
console.error(e)
}