Created
March 17, 2015 14:30
-
-
Save Ianfeather/fefaee82c2ac0e66fddd to your computer and use it in GitHub Desktop.
List files using node and generators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var co = require('co'), | |
fs = require('co-fs'), | |
each = require('co-each'); | |
var dive = function* (path) { | |
var items = yield fs.readdir(path); | |
yield each(items, function* (item) { | |
var subPath = `${path}/${item}`, | |
stat = yield fs.lstat(subPath); | |
if (stat.isDirectory()) { | |
yield dive(subPath) | |
} else { | |
console.log(subPath) | |
} | |
}); | |
} | |
co(function* () { | |
yield dive(process.cwd()) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How the same could look using async/await h/t @rob-mccann