Created
December 24, 2013 20:57
-
-
Save iheart2code/8117743 to your computer and use it in GitHub Desktop.
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
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); | |
}); | |
}; |
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
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