-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
36 lines (34 loc) · 886 Bytes
/
util.js
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
var fs = require('fs');
var path = require('path');
function findFilesByWildcard(pattern) {
var dir = path.dirname(pattern);
var matcher = path.basename(pattern)
.replace(/\./g, '\\.')
.replace(/\?/g, '.?')
.replace(/\*/g, '.*');
var matches = [];
var files = fs.readdirSync(dir);
for (var i in files) {
var file = files[i];
if (file.match(matcher)) {
var stat = fs.statSync(path.join(dir, file));
if (stat.isFile()) matches.push(path.join(dir, file));
}
}
return matches;
}
module.exports = {
findFiles: function(pattern) {
var matches = findFilesByWildcard(pattern);
return matches;
},
exists: function(file) {
try {
fs.statSync(file);
return true;
}
catch (e) {
return false;
}
}
}