Skip to content

Instantly share code, notes, and snippets.

@fbn4sc
Created January 23, 2018 23:53
Show Gist options
  • Save fbn4sc/e73757eea31fdc19a52bfe51378f65a5 to your computer and use it in GitHub Desktop.
Save fbn4sc/e73757eea31fdc19a52bfe51378f65a5 to your computer and use it in GitHub Desktop.
Filter files by extension.
const fs = require("fs");
const dir = process.argv[2];
const ext = process.argv[3];
fs.readdir(dir, (error, files) => {
if (error) throw error;
const re = new RegExp(`\.${ext}$`);
files.map(file => {
if (file.match(re)) console.log(file);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment