Skip to content

Instantly share code, notes, and snippets.

@ibreathebsb
Created June 11, 2019 02:39
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 ibreathebsb/9b62e934bb8eab198ed6f17d7556f869 to your computer and use it in GitHub Desktop.
Save ibreathebsb/9b62e934bb8eab198ed6f17d7556f869 to your computer and use it in GitHub Desktop.
nodejs traverse directory
const fs = require("fs");
const path = require("path");
function traverse(current, cb) {
const stat = fs.statSync(current);
if (stat.isDirectory()) {
const files = fs.readdirSync(current);
files.forEach(file => {
const absPath = path.resolve(current, file);
traverse(absPath, cb);
});
} else {
cb(current);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment