Skip to content

Instantly share code, notes, and snippets.

@cuipengfei
Last active December 31, 2015 03:39
Show Gist options
  • Save cuipengfei/7928903 to your computer and use it in GitHub Desktop.
Save cuipengfei/7928903 to your computer and use it in GitHub Desktop.
learn you node filter list of file names
var fs = require('fs');
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
var dir = process.argv[2];
var postFix = process.argv[3];
fs.readdir(dir, function (err, list) {
list.filter(function (fileName) {
return fileName.endsWith("." + postFix);
}).forEach(function (fileName) {
console.log(fileName);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment