Skip to content

Instantly share code, notes, and snippets.

@SimplGy
Last active May 4, 2019 03:42
Show Gist options
  • Save SimplGy/7865d9ef427444f18ebe2578ae2573fb to your computer and use it in GitHub Desktop.
Save SimplGy/7865d9ef427444f18ebe2578ae2573fb to your computer and use it in GitHub Desktop.
Node - get the contents of all the files in DIR
const fs = require('fs')
const path = require('path')
const DIR = 'input/';
const readFile = name => fs.readFileSync(name);
(async () => {
const files = fs.readdirSync(DIR)
.filter(s => s.match(/\.csv$/)) // only .csv files -- change to whatever you want.
.map(name => path.join(DIR, name))
.map(readFile)
.map(buffer => buffer.toString());
console.log(files);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment