FileSystemManager.mkdir
Overview
Creates a directory.
Usage Limitations
Supported in Basic Library version 3.0.0
or higher.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
dirPath | string | Yes | The path (relative path) of the directory to create. | |
recursive | boolean | false | No | Whether to create the directory after recursively creating its parent directories. If the corresponding parent directory already exists, the parent directory will not be created. For example, if dirPath is "a/b/c/d" and recursive is true, directories "a", "a/b", etc., will be created until "a/b/c/d" is created. |
success | function | No | Callback function to be called when the interface is successfully invoked. | |
fail | function | No | Callback function to be called when the interface fails to be invoked. | |
complete | function | No | Callback function to be called when the interface call ends (both successful and failed calls will execute). |
object.success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
success | string | true - successful |
object.fail Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
errMsg | string | Error message |
success | string | false - unsuccessful |
errMsg Description
Error Message | Description |
---|---|
parameter error: F10001 | Invalid parameter |
fail sdcard not mounted: F10002 | Failed to mount Android sdcard |
fail permission denied: F10005, open ${dirPath} | No write permission for the specified target file path |
fail no such file or directory: F10007, ${dirPath} | Parent directory does not exist (only applicable when recursive = false) |
fail file already exists ${dirPath} | File or directory with the same name already exists (only applicable when recursive = false) |
Example Code
// pages/index/index.js
Page({
mkdir() {
const fs = dlt.getFileSystemManager();
fs.mkdir({
dirPath: `${dlt.env.USER_DATA_PATH}/example`,
recursive: false,
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});