Skip to content

Instantly share code, notes, and snippets.

@wh1tew0lf
Last active September 3, 2019 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wh1tew0lf/7a5bc5df8c13749c5d814844c8fdf6c7 to your computer and use it in GitHub Desktop.
Save wh1tew0lf/7a5bc5df8c13749c5d814844c8fdf6c7 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) done(null, results);
});
} else {
results.push(file);
if (!--pending) done(null, results);
}
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment