HomeDocs
Skip to main content

FileSystemManager.fstat

Introduction

Get the file Stats object.

Usage Restrictions

Supported in basic library version 3.0.0 or higher.

Parameters

Object object

PropertyTypeDefaultRequiredDescription
fdstringYesFile descriptor. The fd is obtained through the FileSystemManager.open interface.
successfunctionNoCallback function that is called when the interface is successfully invoked.
failfunctionNoCallback function that is called when the interface fails to be invoked.
completefunctionNoCallback function that is called when the interface invocation ends (both successful and unsuccessful cases).

object.success Callback Function

Parameters

Object res

PropertyTypeDescription
statsStatsStats object that contains the file's status information.
successstringtrue - Set successfully.

Stats Object Description

PropertyTypeDescription
modestringFile type and access permissions, corresponding to POSIX stat.st_mode.
sizenumberFile size in bytes, corresponding to POSIX stat.st_size.
lastAccessedTimenumberTime when the file was last accessed or executed, UNIX timestamp, corresponding to POSIX stat.st_atime.
lastModifiedTimenumberTime when the file was last modified, UNIX timestamp, corresponding to POSIX stat.st_mtime.

object.fail Callback Function

Parameters

Object res

PropertyTypeDescription
errMsgstringError message.
successstringfalse - Set failed.

errMsg Description

Error MessageDescription
parameter error: F10001Invalid parameters.
bad file descriptor: F10003Invalid file descriptor.
fail permission denied: F10005No 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);
},
});
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.