const fs = require('fs').promises const path = require('path') async function rmdirAsync(filePath) { let stat = await fs.stat(filePath) if(stat.isFile()) { await fs.unlink(filePath) }else { let dirs = await fs.readdir(filePath) dirs = dirs.map(dir => rmdirAsync(path.join(filePath, dir))) await Promise.all(dirs) await fs.rmdir(filePath) } } rmdirAsync('a').then(() => { console.log('删除成功') })
node中实现删除目录的几种方法(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/3cd539a42986cdbbf56daf64863eb15f.html