Instructions for the fs.lstat method in node.js

  • 2020-05-05 10:54:23
  • OfStack

method description:

Gets file information (does not resolve symbolic links).

syntax:


fs.lstat(path, [callback(err, stats)])

Since this method belongs to the fs module, it is necessary to introduce the fs module (var fs= require(" fs "))

before using it

receive parameters:

path     file path

callback   callback, passing two parameters, exception parameter err, file information array stats

stats contains the following information :(the following information is the file information read in the case, not the default)


{
 
 dev : 0 ,
 
 mode : 33206 ,
 
 nlink : 1 ,
 
 uid : 0 ,
 
 gid : 0 ,
 
 rdev : 0 ,
 
 ino : 0 ,
 
 size : 378( byte ) ,
 
 atime : Tue Jun 10 2014 13:57:13 GMT +0800 < Chinese standard time > ,
 
 mtime : Tue Jun 13 2014 09:48:31 GMT +0800 < Chinese standard time > ,
 
 ctime : Tue Jun 10 2014 13:57:13 GMT +0800 < Chinese standard time >
 
}

example:


var fs = require('fs');
fs.lstat('content.txt', function(err, stats){
 if(err){
  throw err;
 }else{
  console.log(stats);
 }
})

source code:


fs.lstat = function(path, callback) {
  callback = makeCallback(callback);
  if (!nullCheck(path, callback)) return;
  binding.lstat(pathModule._makeLong(path), callback);
};


Related articles: