I want to get all the file names in a directory that matches a specific pattern. I found out that I can accomplish this by following these steps:
var fs = require('fs');
fs.readdir( dir, function(err, list) {
if(err)
throw err;
var regex = new RegExp(".*");
list.forEach( function(item) {
if( regex.test(item) )
console.log(item);
});
});
I was wondering if there is another possibility to do this without using a loop, for example. passing regex up fs.readdir(..).
Is this somehow possible, or do I need to use a loop?
source
share