HomeDocs
Skip to main content

FileSystemManager.readdir

Introduction

This function is used to read the list of files in a directory.

Usage Restrictions

This function is supported in basic library version 3.0.0 or higher.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
dirPathstringYesDirectory path to read (relative path).
successfunctionNoCallback function for a successful API call.
failfunctionNoCallback function for a failed API call.
completefunctionNoCallback function for the end of the API call (executed regardless of success or failure).

object.success

Callback Function

Parameters

Object res

PropertyTypeDescription
filesstring[]Array of file names in the specified directory.
successstringtrue - Operation successful.

object.fail

Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstringError message
successstringfalse - Operation failed.

errMsg Explanation

Error messageExplanation
parameter error: F10001Invalid parameter
fail sdcard not mounted: F10002Failed to mount Android sdcard
fail permission denied: F10005, open ${dirPath}No read permission for the specified dirPath
fail no such file or directory: F10007 ${dirPath}.Directory does not exist
fail not a directory ${dirPath}dirPath is not a directory

Sample Code

// pages/index/index.js
Page({
readdir() {
const fs = dlt.getFileSystemManager();
fs.readdir({
dirPath: `${dlt.env.USER_DATA_PATH}/example`,
success(res) {
console.log(res.files);
},
fail(res) {
console.error(res);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.