Last active
December 31, 2015 03:39
-
-
Save cuipengfei/7929452 to your computer and use it in GitHub Desktop.
MAKE IT MODULAR
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 filterListModule = require('./filterListModule'); | |
var dir = process.argv[2]; | |
var postFix = process.argv[3]; | |
filterListModule(dir, postFix, function (err, filteredList) { | |
filteredList.forEach(function (fileName) { | |
console.log(fileName); | |
}); | |
}); |
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 (dir, postFix, callBack) { | |
String.prototype.endsWith = function (suffix) { | |
return this.indexOf(suffix, this.length - suffix.length) !== -1; | |
}; | |
fs.readdir(dir, function (err, list) { | |
if (err) { | |
return callBack(err); | |
} | |
var filteredList = list.filter(function (fileName) { | |
return fileName.endsWith("." + postFix); | |
}); | |
callBack(null, filteredList); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment