forked from tutorialzine/cute-files
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.js
More file actions
53 lines (35 loc) · 694 Bytes
/
scan.js
File metadata and controls
53 lines (35 loc) · 694 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
49
50
51
52
53
var fs = require('fs');
module.exports = function scan(dir, alias){
return {
name: alias,
type: 'folder',
path: alias,
items: walk(dir, alias)
};
};
function walk(dir, prefix){
prefix = prefix || '';
if(!fs.existsSync(dir)){
return [];
}
return fs.readdirSync(dir).filter(function(f){
return f && f[0] != '.'; // Ignore hidden files
}).map(function(f){
var p = (dir + '/' + f).replace('./', ''),
stat = fs.statSync(p);
if(stat.isDirectory()){
return {
name: f,
type: 'folder',
path: prefix + '/' + p,
items: walk(p, prefix)
};
}
return {
name: f,
type: 'file',
path: prefix + '/' + p,
size: stat.size
}
});
};