UNPKG

522 BJavaScriptView Raw
1"use strict";
2
3const fs = require('fs');
4const path = require('path');
5
6
7const 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
29module.exports = readdir;