# Stats|Object FileSystemManager.statSync(string path, boolean recursive)
The synchronous version of FileSystemManager.stat.
# Parameters
# string path
The file/directory path.
# boolean recursive
Start from base library version 2.3.0. Please remaining backward compatible.
Indicates whether to recursively get the Stats information of each file under the directory.
# Return Values
# Stats|Object stats
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.
# Errors
Error Code | Error Message | Description |
---|---|---|
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())
})
}
})