Created
June 11, 2019 02:39
-
-
Save ibreathebsb/9b62e934bb8eab198ed6f17d7556f869 to your computer and use it in GitHub Desktop.
nodejs traverse directory
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
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