-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreadSourceFilesList.js
executable file
·60 lines (48 loc) · 1.67 KB
/
readSourceFilesList.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var fs = require('fs');
var path = require('path');
var diretoryTreeToObj = 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, {name: path.basename(dir), type: 'folder', children: results});
list.forEach(function(file) {
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
diretoryTreeToObj(file, function(err, res) {
results.push({
name: path.basename(file),
type: 'folder',
children: res
});
if (!--pending)
done(null, results);
});
}
else {
if (path.extname(file) == '.csv' && path.basename(file).split("_vel").length == 1){;
results.push({
type: 'file',
name: path.basename(file)
});
}
if (!--pending)
done(null, results);
}
});
});
});
};
var dirTree = ('sourceFiles');
var jsonfile = require('jsonfile')
diretoryTreeToObj(dirTree, function(err, res){
if(err) console.error(err);
console.log(JSON.stringify(res));
var file = 'dataWithFile.json'
jsonfile.writeFile(file, res, function (err) {
console.error(err)
})
});