# FileSystemManager.readdir(Object object)
with Promise style call: Not supported
Mini Program plugin: Support, need to Mini Program base library version no less than 2.19.2
Read list of files in a directory
# parameter
# Object object
attribute | type | Default values | Required | Introductions |
---|---|---|---|---|
dirPath | string | yes | Directory path to read (Local path) |
# Note
- The readdir interface cannot access the file system root path(wxfile://)。 | | success | function | | no | Interface calls the successful callback function | | fail | function | | no | Interface calls failed callback functions | | complete | function | | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) |
# object.success callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
files | Array.<string> | Specifies an array of file names in a directory. |
# object.fail callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
errMsg | string | Error message |
res.errMsg Legal value
value | Introductions | Minimum version |
---|---|---|
fail No such file or directory ${dirPath} | Directory does not exist | |
fail not a directory ${dirPath} | dirPath Not a directory. | |
fail permission denied, open ${dirPath} | Specified filePath Path not read | |
fail sdcard not mounted | Android sdcard Mount failure |
# sample code
const fs = wx.getFileSystemManager()
fs.readdir({
dirPath: `${wx.env.USER_DATA_PATH}/example`,
success(res) {
console.log(res.files)
},
fail(res) {
console.error(res)
}
})
// Synchronous interface
try {
const res = fs.readdirSync(`${wx.env.USER_DATA_PATH}/example`)
console.log(res)
} catch(e) {
console.error(e)
}