-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindFiles.js
More file actions
42 lines (22 loc) · 1.12 KB
/
findFiles.js
File metadata and controls
42 lines (22 loc) · 1.12 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//////////////////////////////////////////////
/* module for exercise 6 NODE MODULES */
//////////////////////////////////////////////
module.exports = function findFiles(dir,ext,callback) {
var fs = require('fs'); // load file system module
var pa = require('path'); // load path module
fs.readdir(dir, function doneReading(err, arrList) { // readFile is asycronous so a call back function is passed.
if(!err){
arrList = arrList.filter(function (item){ // loop through filenames
//return (pa.extname(item) === '.' + ext);
if (pa.extname(item) === '.' + ext) { // check if the filename extension is same as the passed in extension.
return true;
}else{
return false;
}
});
return callback(err,arrList);
}else{
return callback(err); // early return
}
});
};