FileSystemManager.fstat
Introduction
Get the file Stats object.
Usage Restrictions
Supported in basic library version 3.0.0
or higher.
Parameters
Object object
Property | Type | Default | Required | Description |
---|---|---|---|---|
fd | string | Yes | File descriptor. The fd is obtained through the FileSystemManager.open interface. | |
success | function | No | Callback function that is called when the interface is successfully invoked. | |
fail | function | No | Callback function that is called when the interface fails to be invoked. | |
complete | function | No | Callback function that is called when the interface invocation ends (both successful and unsuccessful cases). |
object.success Callback Function
Parameters
Object res
Property | Type | Description |
---|---|---|
stats | Stats | Stats object that contains the file's status information. |
success | string | true - Set successfully. |
Stats Object Description
Property | 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
Property | Type | Description |
---|---|---|
errMsg | string | Error message. |
success | string | false - Set failed. |
errMsg Description
Error Message | Description |
---|---|
parameter error: F10001 | Invalid parameters. |
bad file descriptor: F10003 | Invalid file descriptor. |
fail permission denied: F10005 | No read permission for the specified fd path. |
Sample Code
// pages/index/index.js
Page({
fstat() {
const fs = dlt.getFileSystemManager();
// Open the file
fs.open({
filePath: `${dlt.env.USER_DATA_PATH}/hello.txt`,
flag: 'a+',
success(res) {
// Get the file's status information
fs.fstat({
fd: res.fd,
success(res) {
console.log(res.stats);
},
});
},
});
},
});