Skip to content

Instantly share code, notes, and snippets.

@Isaddo
Created November 3, 2016 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Isaddo/13855725e251993a9dde0d183587280a to your computer and use it in GitHub Desktop.
Save Isaddo/13855725e251993a9dde0d183587280a to your computer and use it in GitHub Desktop.
Get all file paths in a directory recursively
const path = require('path')
const fs = require('fs')
function walkDirSync (dir) {
return fs.readdirSync(dir).reduce((filePaths, fileName) => {
const filePath = path.join(dir, fileName)
if (fs.statSync(filePath).isDirectory()) {
return filePaths.concat(walkDirSync(filePath))
}
return filePaths.concat(filePath)
}, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment