-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06module.js
More file actions
27 lines (21 loc) · 712 Bytes
/
06module.js
File metadata and controls
27 lines (21 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var fs = require('fs');
var path = require('path');
var filteredList = function(pathName, extName, callback){
var listFiles = [];
fs.readdir(pathName, function(err, list){
// don't use throw err here: pass it to the callback so it will
// get passed backto the 'run' module
// why would we *return* the callback, instead of just calling
// it? it doesn't seem to matter on line 21.
if(err){return callback(err);}
for(var i = 0; i < list.length; i++){
if(path.extname(list[i])==='.'+extName){
listFiles.push(list[i]);
}
}
return callback(null, listFiles);
});
}
// could be (except for test specs:
// module.expors.filteredList = filteredList
module.exports = filteredList;