scan.js
1.2 KB
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
'user strict'
var fs = require('fs');
var path = require('path');
module.exports = scan;
function scan(src,callback){
var files=fs.readdirSync(src);
files.forEach(function (item) {
var result={
name:item,
src:path.join(src, item)
};
result.stat=fs.statSync(result.src);
if(callback&&callback(result)&&result.stat.isDirectory()){
scan(result.src,callback)
}
})
}
// function scanFolder(src) {
// var fileList = [],
// folderList = [],
// walk = function (src, fileList, folderList) {
// files = fs.readdirSync(src);
// files.forEach(function (item) {
// var tmpPath = path.join(src, item);
// stats = fs.statSync(tmpPath);
// if (stats.isDirectory()) {
// walk(tmpPath, fileList, folderList);
// folderList.push(tmpPath);
// } else {
// fileList.push(tmpPath);
// }
// });
// };
// walk(src, fileList, folderList);
// return {
// 'files': fileList,
// 'folders': folderList
// }
// }