MCPcopy
hub / github.com/yortus/asyncawait / countFiles

Function countFiles

comparison/countFiles/countFiles-bluebird.js:8–21  ·  view source on GitHub ↗
(dir)

Source from the content-addressed store, hash-verified

6
7/** Returns the number of files in the given directory. */
8var countFiles = function (dir) {
9 return fs.readdirAsync(dir)
10
11 // Get all file stats in parallel.
12 .then(function (files) {
13 var paths = _.map(files, function (file) { return path.join(dir, file); });
14 return Promise.all(_.map(paths, function (path) { return fs.statAsync(path); }));
15 })
16
17 // Count the files.
18 .then(function (stats) {
19 return _.filter(stats, function (stat) { return stat.isFile(); }).length;
20 });
21}
22
23
24function nodeified(dir, callback) { countFiles(dir).nodeify(callback); }

Callers 1

nodeifiedFunction · 0.70

Calls 6

joinMethod · 0.80
allMethod · 0.80
isFileMethod · 0.80
thenMethod · 0.65
mapMethod · 0.65
filterMethod · 0.65

Tested by

no test coverage detected