Having trouble understanding how fs.stat() works

后端 未结 2 1479
情深已故
情深已故 2021-02-07 06:00

I\'m trying to write a function that tells me is a certain path is a directory.

var fs = require(\'fs\');
console.log(\"+++++++++++++++++++++++++++++++++++++++\"         


        
2条回答
  •  逝去的感伤
    2021-02-07 06:31

    You are using the synchronous version, which doesn't use a callback. It simply returns the result instead. So either use the async form fs.stat(path, callback) or use the sync form like this:

    var fs = require('fs');
    console.log("+++++++++++++++++++++++++++++++++++++++");
    var stats = fs.statSync(pathname);
    console.log(stats.isDirectory());
    console.log("+++++++++++++++++++++++++++++++++++++++");
    

提交回复
热议问题