Skip to content

Instantly share code, notes, and snippets.

@annielmenezes
Last active January 22, 2018 13:00
Show Gist options
  • Save annielmenezes/97ccbd7c206b0bb8113cdf957ccb0d82 to your computer and use it in GitHub Desktop.
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
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