function delDir(path){ let files = []; if(fs.existsSync(path)){ files = fs.readdirSync(path); files.forEach((file, index) => { let curPath = path + "/" + file; if(fs.statSync(curPath).isDirectory()){ delDir(curPath); //递归删除文件夹 } else { fs.unlinkSync(curPath); //删除文件 } }); fs.rmdirSync(path); } }
var paths = 'public/resource/test_chudu_CN/';//设置删除路径 delDir(paths);//删除文件夹 fs.mkdirSync('public/resource/test_chudu_CN/','0755');//创建当前文件夹