Skip to content

Commit

Permalink
Added recursive readdir.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Mar 2, 2012
1 parent f3650aa commit 0c0dc81
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/utils.js
Expand Up @@ -315,6 +315,31 @@ utils = new (function () {
}
};

var _readDir = function (dirPath) {
var dir = path.normalize(dirPath)
, paths = []
, ret = [dir];
paths = fs.readdirSync(dir);
paths.forEach(function (p) {
var curr = path.join(dir, p);
console.log(curr);
var stat = fs.statSync(curr);
ret.push(curr);
if (stat.isDirectory()) {
ret = ret.concat(_readDir(curr));
}
});
return ret;
};

this.readdirR = function (dir, opts) {
var options = opts || {}
, format = options.format || 'array'
, ret;
ret = _readDir(dir);
return format == 'string' ? ret.join('\n') : ret;
};

})();

module.exports = utils;

0 comments on commit 0c0dc81

Please sign in to comment.