Skip to content

Instantly share code, notes, and snippets.

@iheart2code
Created December 24, 2013 20:57
Show Gist options
  • Save iheart2code/8117743 to your computer and use it in GitHub Desktop.
Save iheart2code/8117743 to your computer and use it in GitHub Desktop.
var fs = require('fs');
module.exports = function(searchPath, searchExtension, callback)
{
fs.readdir(searchPath, function(err, list)
{
if (err)
{
return callback(err);
}
var filteredList = new Array();
for (var i = 0; i < list.length; i++)
{
var name = list[i];
var startIndex = name.length - searchExtension.length;
var endIndex = name.length;
var extension = name.substring(startIndex, endIndex);
if (extension == searchExtension)
filteredList.push(name);
}
callback(null, filteredList);
});
};
var searchPath = process.argv[2];
var searchExtension = "." + process.argv[3];
var mymodule = require('./filter_module.js');
mymodule(searchPath, searchExtension, function(err, list)
{
if (err)
{
return console.error("There was an error:", err);
}
list.forEach(function (file)
{
console.log(file);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment