title: FileSystemManager.mkdir header: develop nav: api
sidebar: FileSystemManager-mkdir
解释:创建目录。
方法参数:Object object
object参数说明:
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| dirPath | String | 是 | - | 创建的目录路径 |
| recursive | Boolean | 否 | false | 是否在递归创建该目录的上级目录后再创建该目录。如果对应的上级目录已经存在,则不创建该上级目录。如 dirPath 为 a/b/c/d 且 recursive 为 true,将创建 a 目录,再在 a 目录下创建 b 目录,以此类推直至创建 a/b/c 目录下的 d 目录。 |
| success | Function | 否 | - | 接口调用成功的回调函数 |
| fail | Function | 否 | - | 接口调用失败的回调函数 |
| complete | Function | 否 | - | 接口调用结束的回调函数(调用成功、失败都会执行) |
代码示例
- 在 js 文件中
Page({onLoad() {const fs = swan.getFileSystemManager();this.fs = fs;},mkdir() {this.fs.mkdir({dirPath: `${swan.env.USER_DATA_PATH}/mkdir`,success: res => {console.log('mkdir success', res);},fail: err => {console.log('mkdir fail', err)}});}});
