1 | ;
|
2 |
|
3 | const fs = require('fs');
|
4 | const path = require('path');
|
5 |
|
6 |
|
7 | const readdir = function * (dir) {
|
8 | var entries = fs.readdirSync(dir);
|
9 | entries.sort();
|
10 |
|
11 | for(let entry of entries) {
|
12 | let filepath = path.join(dir, entry);
|
13 | try {
|
14 | let stat = fs.statSync(filepath);
|
15 | if(stat.isDirectory()) {
|
16 | for(let subpath of readdir(filepath))
|
17 | yield subpath;
|
18 | } else {
|
19 | yield filepath;
|
20 | }
|
21 | } catch(err) {// stat failure
|
22 | }
|
23 | }
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | module.exports = readdir;
|