Created
February 24, 2014 19:01
-
-
Save oliverswitzer/9194629 to your computer and use it in GitHub Desktop.
An example of a script that will filter files with certain extensions in Node.js
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
// asynchDirList.js | |
var fs = require('fs'); //require node filesystem module | |
var path = require('path'); //require node path module (a couple of tools for reading path names) | |
var pathSupplied = process.argv[2]; | |
var extFilter = process.argv[3]; | |
function extension(element) { | |
var extName = path.extname(element); | |
return extName === '.' + extFilter; | |
}; | |
fs.readdir(pathSupplied, function(err, list) { | |
list.filter(extension).forEach(function(value) { | |
console.log(value); | |
}); | |
}); |
Thanks for this 🙏🏻
Thanks you!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to do this with recursion?