Skip to content

Instantly share code, notes, and snippets.

@aconbere
Created April 23, 2010 21:56
Show Gist options
  • Save aconbere/377231 to your computer and use it in GitHub Desktop.
Save aconbere/377231 to your computer and use it in GitHub Desktop.
fs.walkSync = function (start, callback) {
var stat = fs.statSync(start);
if (stat.isDirectory()) {
var filenames = fs.readdirSync(start)
var coll = filenames.reduce(function (acc, i) {
var abspath = path.join(start, i);
if (fs.statSync(abspath).isDirectory()) {
acc.dirs.push(abspath);
} else {
acc.names.push(abspath);
}
return acc;
}, {"names": [], "dirs": []});
callback(start, coll.dirs, coll.names);
coll.dirs.forEach(function (d) {
fs.walkSync(d, callback);
});
} else {
return null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment