Created
November 21, 2018 20:36
-
-
Save GirlBossRush/ea6593702fa03344721ba8979cdad821 to your computer and use it in GitHub Desktop.
recursive-file-list
This file contains 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
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