Skip to content

Instantly share code, notes, and snippets.

@schipiga
Created September 15, 2017 08:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schipiga/a48bbea439c5cf439147ee1d6b85293b to your computer and use it in GitHub Desktop.
Save schipiga/a48bbea439c5cf439147ee1d6b85293b to your computer and use it in GitHub Desktop.
"use strict"
var fs = require("fs");
var path = require("path");
var traversal = root => {
var files = [];
var folders = [root];
while (folders.length != 0) {
var folder = folders.shift();
var fileNames = fs.readdirSync(folder);
for (var fileName of fileNames) {
var filePath = path.resolve(folder, fileName);
if (fs.statSync(filePath).isDirectory()) {
folders.push(filePath);
} else {
files.push(filePath);
};
};
};
return files;
};
var main = module.exports.main = () => traversal(process.cwd());
if (require.main === module) main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment