-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsong-library.js
39 lines (32 loc) · 1015 Bytes
/
song-library.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
37
38
39
const path = require('path');
const fs = require('fs');
class SongLibrary {
constructor() {
let songs = [];
this.fromDir('./midis','.mid', songs);
this.songs = songs;
this.songs.forEach(s => console.log("Song: " + s));
}
getSongs() {
return this.songs;
}
fromDir(startPath, filter, midi_files) {
if (!fs.existsSync(startPath)){
console.log("no dir ",startPath);
return;
}
let files=fs.readdirSync(startPath);
for (let i = 0 ;i < files.length; i++) {
let filename = path.join(startPath,files[i]);
let stat = fs.lstatSync(filename);
if (stat.isDirectory()){
this.fromDir(filename, filter, midi_files); //recurse
}
else if (filename.indexOf(filter) >= 0) {
midi_files.push(filename);
//console.log('-- found: ',filename);
};
};
};
}
module.exports = SongLibrary;