Last active
July 8, 2022 08:43
-
-
Save pyrsmk/5a97f0cea014e6db8cf294840f3f818f to your computer and use it in GitHub Desktop.
Read a directory recursively
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
import fs from 'fs' | |
import path from 'path' | |
const recursiveReaddirSync = (currentPath : string) => { | |
let results : Array<string> = [] | |
fs.readdirSync(currentPath).forEach(filename => { | |
const filePath = path.resolve(currentPath, filename) | |
const stat = fs.statSync(filePath) | |
if (stat.isDirectory()) { | |
results = results.concat( | |
recursiveReaddirSync(filePath) | |
) | |
return | |
} | |
if (stat.isFile()) { | |
results.push(filePath) | |
return | |
} | |
}) | |
return results | |
} | |
export default recursiveReaddirSync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment