Created
December 31, 2018 18:21
-
-
Save Bengejd/fe7f296dae82e66670d6170369dfcf89 to your computer and use it in GitHub Desktop.
Node.js recursively grab all files in folder
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
function getFiles(dir: string, fileList?: []) { | |
let files = fs.readdirSync(dir); | |
fileList = fileList || []; | |
files.forEach(async (file) => { | |
if(fs.statSync(dir + file).isDirectory()) { | |
// @ts-ignore | |
fileList = await getFiles(dir + file + '/', fileList); | |
} else { | |
// @ts-ignore | |
fileList.push( dir + '/' + file); | |
console.log('Found file at: ', dir + file); | |
} | |
}); | |
return new Promise((resolve) => resolve(fileList)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment