Created
May 6, 2019 12:51
-
-
Save przemek-nowicki/b37a7c5143de2e31b8336d8e3d368ebb to your computer and use it in GitHub Desktop.
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
const fs = require("fs"); | |
const path = require("path"); | |
function getFilesFromDir(dir, fileTypes) { | |
const filesToReturn = []; | |
function walkDir(currentPath) { | |
const files = fs.readdirSync(currentPath); | |
for (let i in files) { | |
const curFile = path.join(currentPath, files[i]); | |
if (fs.statSync(curFile).isFile() && fileTypes.indexOf(path.extname(curFile)) != -1) { | |
filesToReturn.push(curFile); | |
} else if (fs.statSync(curFile).isDirectory()) { | |
walkDir(curFile); | |
} | |
} | |
}; | |
walkDir(dir); | |
return filesToReturn; | |
} | |
module.exports = getFilesFromDir; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment