deleteFolderRecursive.js 480 B

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