Last active
January 22, 2018 13:00
-
-
Save annielmenezes/97ccbd7c206b0bb8113cdf957ccb0d82 to your computer and use it in GitHub Desktop.
Node.js function that spider over directory and return a matrix of paths
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 { readdirSync, statSync } = require("fs"); | |
const { dirname, join } = require("path"); | |
// Usage: | |
// const walkSync = require("walk-dir-sync"); | |
// console.log(walkSync(path)); | |
// return a matrix of files path | |
// [ [path, path], [path, path] ] | |
const walkSync = d => | |
statSync(d).isDirectory() ? readdirSync(d).map(f => walkSync(join(d, f))) : d; | |
module.exports = walkSync; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment