Use nodejs to view file information

We use nodejs to get the file Xinxin

fs.stat(path,callback)

Description of parameters

  • path - file name
  • callback - callback function, with two parameters (err, stats)

After fs.stat(path) is executed, it will return an instance of the stats class to its callback function. You can use the methods in the stats class to determine the attributes in the file

Next we prepare an example

var fs = require("fs");

console.log("准备打开文件!");
fs.stat('input.txt', function (err, stats) {
   if (err) {
       return console.error(err);
   }
   console.log(stats);
   console.log("读取文件信息成功!");

   // 检测文件类型
   console.log("是否为文件(isFile) ? " + stats.isFile());
   console.log("是否为目录(isDirectory) ? " + stats.isDirectory());    
});

This will print the information of the file

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325504134&siteId=291194637