importfsfrom"fs";// preset -> base path + new pathfunctionreadFiles(preset,paths,files){paths.forEach(path=>{if(fs.lstatSync(preset+path).isFile()){files.push(preset+path);}else{constdirs=fs.readdirSync(preset+path);readFiles(preset+path+"/",dirs,files);}});}// base -> base pathfunctionreadAllFiles(base){constfiles=[];constdirs=fs.readdirSync(base);readFiles(base,dirs,files);returnfiles;}// read filesconstfiles=readAllFiles("./");// print filesfiles.forEach(file=>{constcontent=fs.readFileSync(file,{encoding:"utf-8"});console.log({[file]:content})})
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)