added ability to ignore dotfiles in readdir

This commit is contained in:
Erik 2022-01-11 22:54:52 +02:00
parent 3f066f8cbf
commit e07acc92e3
No known key found for this signature in database
GPG Key ID: FEFF4B220DDF5589

View File

@ -34,13 +34,22 @@ class Util {
});
}
static readdirRecursive(directory) {
/**
* Read directory recursively and return all file paths
* @static
* @param {string} directory Full path to target directory
* @param {boolean} [ignoreDotfiles=true]
* @return {string[]} Array with the paths to the files within the directory
* @memberof Util
*/
static readdirRecursive(directory, ignoreDotfiles = true) {
const result = [];
(function read(directory) {
const files = fs.readdirSync(directory);
for (const file of files) {
if (file.startsWith('.') && ignoreDotfiles) continue;
const filePath = path.join(directory, file);
if (fs.statSync(filePath).isDirectory()) {