A
A
artmirarmi2018-06-25 09:06:12
JavaScript
artmirarmi, 2018-06-25 09:06:12

How to find out the number of files in a directory in node.js?

How to find out the number of files in a directory in node.js?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlexKindGeek, 2018-06-25
@AlexKindGeek

const fs = require('fs');
const dir = './directory';

fs.readdir(dir, (err, files) => {
  console.log(files.length);
});

B
BarryHAllen, 2018-06-25
@BarryHAllen

const FileHound = require('filehound');
const a = FileHound.create()
        .discard(discard)
        .depth(depth)
        .paths(path)
        .ext(ext)
        .find();

a.then(function(files){
    console.log(files.length);
}

Docs:
https://nspragg.github.io/filehound/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question