数组要定义在函数外部
const fs = require('fs');
let arr1 = [];
function fn(dir) {
let arr = fs.readdirSync(dir);
for (let i of arr) {
let obj = fs.statSync(`${dir}/${i}`);
if (obj.isDirectory()) {
fn(`${dir}/${i}`);
} else{
arr1.push(`${dir}/${i}`);
}
}
return arr1;
}
module.exports = {fn};