1.0.0 • Published 4 years ago
mty_main_mty v1.0.0
删除文件子目录
const fs = require('fs');
const { resolve } = require('path');
//读取文件夹子目录
fs.readdir('qwe',(err,arr) => {
//遍历文件夹里的文件及文件夹
let result = arr.map(item =>{
item = 'qwe/' + item;
return new Promise((resolve,reject) => {
fs.unlink(item,(err) => {
if(err){
reject(err);
return;
}
resolve();
})
})
})
Promise.all(result).then(() =>{
fs.rmdirSync('qwe');
})
})
1.0.0
4 years ago