I want to check folder with names which are present in array and only select them which are present inside array list but with if condition and return the value which are present inside FileArray
let extensionArray = [".html", ".htm", ".aspx"];
let fileArray = [
"index.html",
"index.htm",
"index.aspx",
"Index.html",
"Index.htm",
"Index.aspx",
"default.html",
"default.htm",
"default.aspx",
"Default.html",
"Default.htm",
"Default.aspx",
];
if(!extensionArray.include(true){
if(!fileArray.inclue(true){
// return the output
}
}
I have checked one of the post in which file can be checked from all the folder and subfolder
but I don't know where to apply my condition to check the extension and file name and then return it.
code is as follow :-
const fs = require('fs');
const path = require('path');
async function getFile(dir) {
let files = await fs.readdir(dir);
files = await Promise.all(
files.map(async (file) => {
const filePath = path.join(dir, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) return getFile(filePath);
else if (stats.isFile()) return filePath;
})
);
return files.reduce((all, folderContents) => all.concat(folderContents), []);
}