2020-07-08 14:53:07 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require("path")
|
|
|
|
|
|
|
|
const getAllFiles = function(dirPath, ext, arrayOfFiles = []) {
|
|
|
|
const files = fs.readdirSync(dirPath)
|
|
|
|
|
|
|
|
files.forEach(file => {
|
2020-07-16 15:20:06 +00:00
|
|
|
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
|
|
|
|
arrayOfFiles = getAllFiles(path.join(dirPath, file), ext, arrayOfFiles)
|
2020-07-08 14:53:07 +00:00
|
|
|
} else if (!ext || file.endsWith(ext)) {
|
2020-07-16 15:20:06 +00:00
|
|
|
arrayOfFiles.push(path.join(__dirname, dirPath, file))
|
2020-07-08 14:53:07 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return arrayOfFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getAllFiles
|
|
|
|
};
|