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
Property | Type | Default | Required | Description |
---|---|---|---|---|
dirPath | string | Yes | Directory path to read (relative path). | |
success | function | No | Callback function for a successful API call. | |
fail | function | No | Callback function for a failed API call. | |
complete | function | No | Callback function for the end of the API call (executed regardless of success or failure). |
object.success
Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
files | string[] | Array of file names in the specified directory. |
success | string | true - Operation successful. |
object.fail
Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
errMsg | string | Error message |
success | string | false - Operation failed. |
errMsg Explanation
Error message | Explanation |
---|---|
parameter error: F10001 | Invalid parameter |
fail sdcard not mounted: F10002 | Failed 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);
},
});
},
});