Created
June 18, 2015 11:01
-
-
Save vird/db50ff47f0066903f34e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var _ = require('lodash'); | |
/** Returns the number of files in the given directory. */ | |
var countFiles = function (dir, callback) { | |
// Get all directory entries. | |
fs.readdir(dir, function (err, files) { | |
if (err) { callback(err); return; } | |
callback(null, files.length); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var _ = require('lodash'); | |
/** Returns the number of files in the given directory. */ | |
var countFiles = function (dir) { | |
var files = fs.readdirSync(dir); | |
return files.length; | |
}; | |
function nodeified(dir, callback) { | |
try { | |
callback(null, countFiles(dir)); | |
} | |
catch (err) { | |
callback(err); | |
} | |
} | |
module.exports = nodeified; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment