1 |
|
2 | const fs = require('fs');
|
3 | const Path = require('path');
|
4 |
|
5 | const 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 |
|
19 | module.exports = deleteFolderRecursive
|