Created
June 29, 2021 13:19
-
-
Save JayWood/50e265e72c0f4129077b0d7cbfc6d834 to your computer and use it in GitHub Desktop.
A function to recursively get all files in an array.
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
/** | |
* Gets all files as the function says. | |
* | |
* @param {string} dirPath | |
* @param {string[]} arrayOfFiles | |
* @returns {*|string[]} | |
*/ | |
const getAllFiles = function(dirPath, arrayOfFiles) { | |
const files = fs.readdirSync(dirPath) | |
arrayOfFiles = arrayOfFiles || [] | |
files.forEach(function(file) { | |
if (fs.statSync(dirPath + "/" + file).isDirectory()) { | |
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles) | |
} else { | |
// Get only PHP and CSS, minus the .min files | |
if ( ! file.includes( '.min' ) && extensions.includes( path.extname( file ) ) ) { | |
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file)) | |
} | |
} | |
}) | |
return arrayOfFiles | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment