UNPKG

480 BJavaScriptView Raw
1
2const fs = require('fs');
3const Path = require('path');
4
5const deleteFolderRecursive = function(path) {
6 if (fs.existsSync(path)) {
7 fs.readdirSync(path).forEach((file, index) => {
8 const curPath = Path.join(path, file);
9 if (fs.lstatSync(curPath).isDirectory()) { // recurse
10 deleteFolderRecursive(curPath);
11 } else { // delete file
12 fs.unlinkSync(curPath);
13 }
14 });
15 fs.rmdirSync(path);
16 }
17};
18
19module.exports = deleteFolderRecursive