DEV Community

Aurélien Delogu
Aurélien Delogu

Posted on

2 1

Code snippet: How to browse a directory recursively

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

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more