HomeDocs
Skip to main content

FileSystemManager.mkdir

Overview

Creates a directory.

Usage Limitations

Supported in Basic Library version 3.0.0 or higher.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
dirPathstringYesThe path (relative path) of the directory to create.
recursivebooleanfalseNoWhether 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.
successfunctionNoCallback function to be called when the interface is successfully invoked.
failfunctionNoCallback function to be called when the interface fails to be invoked.
completefunctionNoCallback function to be called when the interface call ends (both successful and failed calls will execute).

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
successstringtrue - successful

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstringError message
successstringfalse - unsuccessful

errMsg Description

Error MessageDescription
parameter error: F10001Invalid parameter
fail sdcard not mounted: F10002Failed 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);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.