From e07acc92e3eb022fc1ade9fe1fa411639b1a87d4 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 11 Jan 2022 22:54:52 +0200 Subject: [PATCH] added ability to ignore dotfiles in readdir --- src/Util.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Util.js b/src/Util.js index e304ebf..fc13229 100644 --- a/src/Util.js +++ b/src/Util.js @@ -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()) {