Created
October 14, 2020 14:00
-
-
Save evanlucas/cd9fccb0d8fa2e60485e9702734bb205 to your computer and use it in GitHub Desktop.
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' | |
const fs = require('fs').promises | |
const path = require('path') | |
async function* getPaths(p, depth = 0) { | |
const dir = await fs.opendir(p, { | |
bufferSize: 1 | |
}) | |
for await (const entry of dir) { | |
if (!entry.isDirectory()) continue | |
yield entry | |
if (depth < 2) { | |
const fp = path.join(p, entry.name) | |
yield* getPaths(fp, depth + 1) | |
} | |
} | |
} | |
;(async () => { | |
for await (const thing of getPaths('/usr/sbin')) { | |
console.log(thing) | |
} | |
})() | |
.then(() => console.log('done')) | |
.catch((err) => { | |
console.error(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output of that for me is this: