node递归删除文件
const fs = require('fs');
const path = require('path');
const join = path.join;
function walk(dir,suffix='.iml') {
var result = [];
var list = fs.readdirSync(dir);
list.forEach((file) => {
var currentPath = join(dir, file);
var stat = fs.statSync(currentPath);
if (stat && stat.isDirectory()) {
result = result.concat(walk(currentPath,suffix));
} else {
if (path.extname(currentPath) === suffix) {
result.push(currentPath);
}
}
});
return result;
}
const basePath = path.resolve('E:/code');
const list = walk(basePath);
list && list.forEach((file) => {
fs.unlinkSync(file);
});