Created
February 11, 2018 10:55
-
-
Save NitsanBaleli/3066b0b8dc3cf8100fecefc5b3c7f77e to your computer and use it in GitHub Desktop.
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 fs = require('fs'); | |
const path = require('path'); | |
const allFilesSync = (dir, fileList = [], prefix = '') => { | |
fs.readdirSync(dir).forEach(file => { | |
const filePath = path.join(dir, file) | |
fileList.push( | |
fs.statSync(filePath).isDirectory() | |
? {file: allFilesSync(filePath, undefined, file)} | |
: `${prefix}.${path.parse(file).name}` | |
) | |
}) | |
return fileList | |
} | |
console.log(allFilesSync('./')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment