-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect.js
More file actions
48 lines (37 loc) · 833 Bytes
/
collect.js
File metadata and controls
48 lines (37 loc) · 833 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var fs = require('fs');
var path = require('path');
module.exports = function collect(dir, collection) {
return {
name: collection,
type: 'folder',
path: collection,
items: walkthru(dir, collection)
};
};
function walkthru(dir, prefix){
prefix = prefix || '';
if(!fs.existsSync(dir)){
return [];
}
return fs.readdirSync(dir).filter(function(f) {
// return f && f[0] != '.';
return f.substr(-4) === '.mp3';
}).map(function(f) {
var p = path.join(dir, f),
stats = fs.statSync(p);
if(stats.isDirectory()) {
return {
name: f,
type: 'folder',
path: path.join(prefix, p),
items: walkthru(p, prefix)
};
}
return {
name: f,
type: 'file',
path: path.join(prefix, p),
size: stats.size
}
});
};