how to determine whether the directory is empty directory with nodejs

荒凉一梦 提交于 2019-12-05 01:00:27

I guess I'm wondering why you don't just list the files in the directory and see if you get any files back?

fs.readdir(dirname, function(err, files) {
    if (err) {
       // some sort of error
    } else {
       if (!files.length) {
           // directory appears to be empty
       }
    }
});

You could, of course, make a synchronous version of this too.

This, of course, doesn't guarantee that there's nothing in the directory, but it does mean there are no public files that you have permission to see there.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!