HomeDocs
Skip to main content

FileSystemManager.stat

Introduction

Get the file Stats object.

Usage Limitations

Supported in the base library version 3.0.0 or higher.

Parameters

Object object

AttributeTypeDefaultRequiredDescription
pathstringYesFile/directory path (relative path)
recursivestringNoWhether to recursively obtain the Stats information for each file in the directory
successfunctionNoCallback function for a successful API call
failfunctionNoCallback function for a failed API call
completefunctionNoCallback function for the end of the API call (executed for both successful and failed calls)

object.success

Callback Function

Parameters

Object res

AttributeTypeDescription
statsStats[]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.
successstringtrue-Set successfully

Stats Object Description

AttributeTypeDescription
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

AttributeTypeDescription
errMsgstringError message
successstringfalse-Set failed

errMsg Description

Error MessageDescription
parameter error: F10001Invalid parameters
fail sdcard not mounted: F10002Android 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);
},
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.