count-files
Advanced tools
Comparing version 1.0.0 to 1.0.1
18
index.js
@@ -7,5 +7,6 @@ var fs = require('fs') | ||
function countFiles (dir, opts, cb) { | ||
if (typeof(opts) === 'function') return countFiles(dir, null, opts) | ||
if (typeof (opts) === 'function') return countFiles(dir, null, opts) | ||
var filter = opts && opts.filter || function (filename) { return true } | ||
if (!opts) opts = {} | ||
var filter = opts.filter || function (filename) { return true } | ||
var count = { | ||
@@ -32,6 +33,13 @@ files: 0, | ||
fs.stat(filePath, function (err, stats) { | ||
if (err) return cb(err) | ||
if (err && err.code === 'ENOENT') { | ||
// symlinks | ||
pending -= 1 | ||
if (!pending) return cb(null, count) | ||
return | ||
} else if (err) { | ||
cb(err) | ||
} | ||
if (stats.isDirectory()) { | ||
count.dirs += 1 | ||
countFiles(filePath, function (err, res) { | ||
countFiles(filePath, opts, function (err, res) { | ||
if (err) return cb(err) | ||
@@ -53,2 +61,2 @@ count.dirs += res.dirs | ||
}) | ||
} | ||
} |
{ | ||
"name": "count-files", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "count files in a directory recursively", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2185
52