# FileSystemManager.state(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
Get Files Stats object
# parameter
# Object object
attribute | type | Default values | Required | Introductions | Minimum version |
---|---|---|---|---|---|
path | string | yes | file/Directory path (Local path) | ||
recursive | boolean | false | no | For each file in the directory Stats information | 2.3.0 |
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 |
---|---|---|
stats | Stats/Array.<Stats> | when recursive for false When res.stats It's a... Stats Object. when recursive for true and path Is a directory path, res.stats It's a... Array, each item in an array is an object, and each object contains path and stats。 |
# object.fail callback
# parameter
# Object res
attribute | type | Introductions |
---|---|---|
errMsg | string | Error message |
res.errMsg Legal value
value | Introductions | Minimum version |
---|---|---|
fail permission denied, open ${path} | Specified path Path not read | |
fail No such file or directory ${path} | File does not exist | |
fail sdcard not mounted | Android sdcard Mount failure |
# sample code
recursive for false time
let fs = wx.getFileSystemManager()
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
success: res => {
console.log(res.stats.isDirectory())
}
})
recursive for true time
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
recursive: true,
success: res => {
Object.keys(res.stats).forEach(path => {
let stats = res.stats[path]
console.log(path, stats.isDirectory())
})
}
})