UNPKG

448 BJavaScriptView Raw
1const fs = require('fs');
2
3function delDir(path){
4 let files = [];
5 if(fs.existsSync(path)){
6 files = fs.readdirSync(path);
7 files.forEach((file, index) => {
8 let curPath = path + "/" + file;
9 if(fs.statSync(curPath).isDirectory()){
10 delDir(curPath); //递归删除文件夹
11 } else {
12 fs.unlinkSync(curPath); //删除文件
13 }
14 })
15 fs.rmdirSync(path)
16 }
17}
18
19module.exports = delDir
\No newline at end of file