Created
January 23, 2018 23:53
-
-
Save fbn4sc/e73757eea31fdc19a52bfe51378f65a5 to your computer and use it in GitHub Desktop.
Filter files by extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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