fs.lstatSync()方法用于同步返回有关用于引用文件或目录的符号链接的信息。 fs.Stat对象返回几个字段和方法,以获取有关文件的更多详细信息。
用法:
fs.lstatSync( path, options )
参数:该方法接受上述和以下所述的两个参数:
- path:它是一个字符串,缓冲区或URL,其中包含符号链接的路径。
- options:该对象可用于指定将影响输出的可选参数。它具有一个可选参数:
- bigint:它是一个布尔值,它指定fs.Stats对象中返回的数值是否为bigint。默认值为false。
返回值:它返回一个fs.Stats对象,其中包含符号链接的详细信息。
以下示例说明了Node.js中的fs.lstatSync()方法:
范例1:本示例使用fs.lstatSync()方法获取文件符号链接的详细信息。
// Node.js program to demonstrate the
// fs.lstatSync() method
// Import the filesystem module
const fs = require('fs');
fs.symlinkSync(__dirname + "\\example_file.txt",
"symlinkToFile", 'file');
console.log("Symlink to file created")
statsObj = fs.lstatSync("symlinkToFile");
console.log("Stat of symlinkToFile")
console.log(statsObj);输出:
Symlink to file created
Stat of symlinkToFile
Stats {
dev:3229478529,
mode:41398,
nlink:1,
uid:0,
gid:0,
rdev:0,
blksize:4096,
ino:281474976780954,
size:49,
blocks:0,
atimeMs:1585207963423.2476,
mtimeMs:1585207963423.2476,
ctimeMs:1585207963423.2476,
birthtimeMs:1585207963423.2476,
atime:2020-03-26T07:32:43.423Z,
mtime:2020-03-26T07:32:43.423Z,
ctime:2020-03-26T07:32:43.423Z,
birthtime:2020-03-26T07:32:43.423Z
}
范例2:本示例使用fs.lstatSync()方法获取指向文件夹的符号链接的详细信息。
// Node.js program to demonstrate the
// fs.lstatSync() method
// Import the filesystem module
const fs = require('fs');
fs.symlinkSync(__dirname + "\\example_directory",
"symlinkToDir", 'dir');
console.log("Symlink to directory created")
statsObj = fs.lstatSync("symlinkToDir");
console.log("Stat of symlinkToDir")
console.log(statsObj);输出:
Stat of symlinkToDir
Stats {
dev:3229478529,
mode:41398,
nlink:1,
uid:0,
gid:0,
rdev:0,
blksize:4096,
ino:281474976780955,
size:50,
blocks:0,
atimeMs:1585208001112.3284,
mtimeMs:1585208001112.3284,
ctimeMs:1585208001112.3284,
birthtimeMs:1585208001112.3284,
atime:2020-03-26T07:33:21.112Z,
mtime:2020-03-26T07:33:21.112Z,
ctime:2020-03-26T07:33:21.112Z,
birthtime:2020-03-26T07:33:21.112Z
}
参考: https://nodejs.org/api/fs.html#fs_fs_lstatsync_path_options
相关用法
- Node.js GM drawCircle()用法及代码示例
- Node.js GM drawBezier()用法及代码示例
- Node.js GM drawPolyline()用法及代码示例
- Node.js GM drawArc()用法及代码示例
- Node.js GM drawEllipse()用法及代码示例
- Node.js GM monochrome()用法及代码示例
- Node.js GM equalize()用法及代码示例
- Node.js GM enhance()用法及代码示例
- Node.js GM drawPolygon()用法及代码示例
- Node.js GM whitePoint()用法及代码示例
注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 Node.js | fs.lstatSync() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
