forked from mawalu/node-music-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
39 lines (37 loc) · 935 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
37
38
39
// This file is a bunch of utility functions
var fs = require('fs');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) done(null, results);
});
} else {
results.push(file);
if (!--pending) done(null, results);
}
});
});
});
}
exports.walk = walk;
var mkdir = function(dir, done) {
fs.exists(dir, function(exists){
if(!exists){
fs.mkdir(dir, '0777', function(){
done();
});
} else {
done();
}
});
}
exports.mkdir = mkdir;