FileSystemManager.stat
Introduction
Get the file Stats object.
Usage Limitations
Supported in the base library version 3.0.0
or higher.
Parameters
Object object
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
path | string | Yes | File/directory path (relative path) | |
recursive | string | No | Whether to recursively obtain the Stats information for each file in the directory | |
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 for both successful and failed calls) |
object.success
Callback Function
Parameters
Object res
Attribute | Type | Description |
---|---|---|
stats | 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 Array, and each item in the array is an object that contains path and stats. |
success | string | true-Set successfully |
Stats Object Description
Attribute | Type | Description |
---|---|---|
mode | string | File type and access permissions, corresponding to POSIX stat.st_mode |
size | number | File size in bytes, corresponding to POSIX stat.st_size |
lastAccessedTime | number | Time when the file was last accessed or executed, UNIX timestamp, corresponding to POSIX stat.st_atime |
lastModifiedTime | number | Time when the file was last modified, UNIX timestamp, corresponding to POSIX stat.st_mtime |
object.fail
Callback Function
Parameters
Object res
Attribute | Type | Description |
---|---|---|
errMsg | string | Error message |
success | string | false-Set failed |
errMsg Description
Error Message | Description |
---|---|
parameter error: F10001 | Invalid parameters |
fail sdcard not mounted: F10002 | Android sdcard mount failed |
fail permission denied: F10005, open "${filePath}" | No write permission for the specified filePath path |
fail no such file or directory: F10007 "${path}" | File/directory does not exist |
Sample Code
// pages/index/index.js
Page({
stat() {
const fs = dlt.getFileSystemManager();
fs.stat({
path: `${dlt.env.USER_DATA_PATH}/testDir`,
recursive: true,
success: (res) => {
console.log(res);
},
});
},
});