constfs=require('fs');constpath=require("path");functiongetFiles(dir, files = []) {// Get an array of all files and directories in the passed directory using fs.readdirSyncconstfileList=fs.readdirSync(dir);// Create the full path of the file/directory by concatenating the passed directory and file/directory namefor (constfileof fileList) {constname=`${dir}/${file}`// Check if the current file/directory is a directory using fs.statSyncif (fs.statSync(name).isDirectory()) {console.log(name);cleanEmptyFoldersRecursively(name);// If it is a directory, recursively call the getFiles function with the directory path and the files array// getFiles(name, files) } else {// If it is a file, push the full path to the files arrayfiles.push(name) } }return files}functioncleanEmptyFoldersRecursively(folder) {var isDir =fs.statSync(folder).isDirectory();if (!isDir) {return; }var files =fs.readdirSync(folder);if (files.length>0) {files.forEach(function(file) {var fullPath =path.join(folder, file);cleanEmptyFoldersRecursively(fullPath); });// re-evaluate files; after deleting subfolder// we may have parent folder empty now files =fs.readdirSync(folder); }if (files.length==0) {console.log("removing: ", folder);fs.rmdirSync(folder);return; }}getFiles('files');