Skip to content

Instantly share code, notes, and snippets.

@AlecTaylor AlecTaylor/fileList.js
Last active Mar 17, 2016

What would you like to do?
Extension of to support excludeDirs array argument
import * as fs from 'fs';
import * as path from 'path';
// Trivial to extend with `includeDirs`, just follow same pattern
function fileList(dir, excludeDirs?) {
return fs.readdirSync(dir).reduce(function (list, file) {
const name = path.join(dir, file);
if (fs.statSync(name).isDirectory()) {
if (excludeDirs && excludeDirs.length) {
excludeDirs = => path.normalize(d));
const idx = name.indexOf(path.sep);
const directory = name.slice(0, idx === -1 ? name.length : idx);
if (excludeDirs.indexOf(directory) !== -1)
return list;
return list.concat(fileList(name, excludeDirs));
return list.concat([name]);
}, []);
console.log(fileList('.', ['node_modules', 'typings', 'bower_components']));

This comment has been minimized.

Copy link

SalahAdDin commented Mar 17, 2016

Ok, i have problem with this man:

                excludeDirs = (d) {

TypeError: is not a function
    at webpack.config.babel.js:24:43
    at Array.reduce (native)
    at fileList (webpack.config.babel.js:20:32)
    at Object.<anonymous> (webpack.config.babel.js:69:20)
    at Module._compile (module.js:413:34)
    at loader (/run/media/salahaddin/Datos/Proyectos/Desarrollo/django-jet/jet/static/jet/node_modules/babel-register/lib/node.js:126:5)
    at Object.require.extensions.(anonymous function) [as .js] (/run/media/salahaddin/Datos/Proyectos/Desarrollo/django-jet/jet/static/jet/node_modules/babel-register/lib/node.js:136:7)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

I don't understand why, i'm using it in webpack with babel, webpack.config.babel.js, using this:

  "presets": [


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.