filesystemmanager.statsync(string path, boolean recursive)
基础库 或更高版本; 若版本较低,建议采取 兼容处理 。
主体: 企业支付宝小程序 、 个人支付宝小程序
相关文档: filesystemmanager.stat 、 stats 概览 、 本地文件
同步获取文件 stats 对象。
string path
必填。
本地文件/目录路径。支持 本地文件。
boolean recursive
可选,默认为 false。
是否递归获取目录下的每个文件的 stats 信息。
object
属性 | 类型 | 描述 |
---|---|---|
stats | object | 描述 path 的 stats 或 stats 字典(当 path 为目录且 recursive 为 true 时。字典的 key 为目录中的子路径)。 |
接口调用出错时,返回 object 对象,error
属性为错误码,errormessage
属性为错误消息。
错误码 | 错误消息 | 凯发app官方网站的解决方案 |
---|---|---|
2 | invalid parameter! |
无效参数,请检查入参,参考类型和必填。 |
10022 | 文件不存在 {path} |
请检查文件是否存在。 |
filesystemmanager.statsync(string path, boolean recursive)
recursive 为 true 时调用
recursive 为 false 或 path 是一个文件路径时返回的 res
recursive 为 true 且 path 是一个目录路径时返回的 res
const fs = my.getfilesystemmanager();
const result = fs.statsync(`${my.env.user_data_path}/testdir`);
if (result.stats) {
console.log(result.stats);
}
const result = fs.statsync(`${my.env.user_data_path}/testdir`, true);
if (result.stats) {
for (const path of object.keys(result.stats)) {
const statsobj = result.stats[path];
console.log(path, statsobj.stats.isdirectory());
}
}
{
"stats": {
"mode": 16877,
"size": 64,
"lastaccessedtime": 1685956462857,
"lastmodifiedtime": 1685956462857,
"isdirectory": ƒ (),
"isfile": ƒ ()
}
}
{
"stats": {
"/": {
"path": "/",
"stats": {
"mode": 16877,
"size": 96,
"lastaccessedtime": 1685952220258,
"lastmodifiedtime": 1685956462857,
"isdirectory": ƒ (),
"isfile": ƒ ()
}
}
}
}