Node.js: How to check if folder is empty or not with out uploading list of files

后端 未结 6 1977
日久生厌
日久生厌 2021-02-12 18:59

I am using Node.js.

I want to check if folder is empty or not? One option is to use fs.readdir but it loads whole bunch of

6条回答
  •  感动是毒
    2021-02-12 19:36

    Just like to add that there's a node module extfs which can be used to check if a directory is empty using the function isEmpty() as shown by the code snippet below:

    var fs = require('extfs');
    
    fs.isEmpty('/home/myFolder', function (empty) {
      console.log(empty);
    });
    

    Check out the link for documentation regarding the synchronous version of this function.

提交回复
热议问题