# FileSystemManager.stat(Object object)
Gets the Stats object of the file.
# Parameters
# Object object
Property | Type | Default Value | Required | Description | Minimum Version |
---|---|---|---|---|---|
path | string | Yes | File/directory path | ||
recursive | boolean | false | No | Indicates whether to recursively get the Stats information of each file under the directory | 2.3.0 |
success | function | No | The callback function for a successful API call | ||
fail | function | No | The callback function for a failed API call | ||
complete | function | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
# object.success callback function
# Parameters
# Object res
Property | Type | Description |
---|---|---|
stats | Stats/Object | When "recursive" is false, "res.stats" is a Stats object. When "recursive" is true and "path" is a directory path, "res.stats" is an Object, "key" is a relative path with "path" as the root path, and "value" is a Stats object in the path. |
# object.fail callback function
# Parameters
# Object res
Property | Type | Description |
---|---|---|
errMsg | string | Error message |
Valid values of res.errMsg
Value | Description | Minimum Version |
---|---|---|
fail permission denied, open ${path} | No read permission on the specified path | |
fail no such file or directory ${path} | File does not exist |
# Sample Code
When recursive is false
let fs = wx.getFileSystemManager()
fs.stat({
path: `${wx.env.USER_DATA_PATH}/testDir`,
success: res => {
console.log(res.stats.isDirectory())
}
})
When recursive is true
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())
})
}
})