Created
November 21, 2018 07:37
-
-
Save strix/eecc35c3abbfe109bcec4f727100e072 to your computer and use it in GitHub Desktop.
Recursive file crawling with async await
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
| const findFiles = async (startPath) => { | |
| const results = [] | |
| const findRecursive = async (recursiveStartPath) => { | |
| const files = await readdir(recursiveStartPath) | |
| for (const file of files) { | |
| const currentFile = `${recursiveStartPath}/${file}` | |
| const stats = await stat(currentFile) | |
| if (stats.isFile()) { | |
| results.push(path.resolve(currentFile)) | |
| } else if (stats.isDirectory()) { | |
| await findRecursive(currentFile) | |
| } | |
| } | |
| return results | |
| } | |
| const foundFiles = await findRecursive(startPath) | |
| return foundFiles | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment