Skip to content

Instantly share code, notes, and snippets.

@GirlBossRush
Created November 21, 2018 20:36
Show Gist options
  • Save GirlBossRush/ea6593702fa03344721ba8979cdad821 to your computer and use it in GitHub Desktop.
Save GirlBossRush/ea6593702fa03344721ba8979cdad821 to your computer and use it in GitHub Desktop.
recursive-file-list
const fs = require('fs')
const {promisify} = require('util')
const path = require('path')
const readdirP = promisify(fs.readdir)
const statP = promisify(fs.stat)
async function recursiveFileList (basePath, callback) {
const filePaths = await readdirP(basePath)
for (filePath of filePaths) {
const qualifiedPath = path.join(basePath, filePath)
const fileStat = await statP(qualifiedPath)
if (fileStat.isDirectory()) {
recursiveFileList(qualifiedPath, callback)
} else {
callback(qualifiedPath)
}
}
}
recursiveFileList('./foo', async (filePath) => {
console.log('^^', filePath)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment