Count the number of files in a directory using JavaScript/nodejs?

前端 未结 7 2313
小蘑菇
小蘑菇 2021-02-12 17:54

How can I count the number of files in a directory using nodejs with just plain JavaScript or packages? I want to do something like this:

How to count the n

7条回答
  •  甜味超标
    2021-02-12 18:48

    Okay, I got a bash script like approach for this:

    const shell = require('shelljs')
    const path = require('path')
    
    module.exports.count = () => shell.exec(`cd ${path.join('path', 'to', 'folder')} || exit; ls -d -- */ | grep 'page-*' | wc -l`, { silent:true }).output
    

    That's it.

提交回复
热议问题