rmdir.js 888 B

12345678910111213141516171819202122232425262728
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. const fs = require('fs');
  6. const path = require('path');
  7. const target = path.join(process.cwd(), process.argv[2]);
  8. if (fs.existsSync(target)) {
  9. rmDir(target);
  10. }
  11. console.log(`Deleted ${process.argv[2]}`);
  12. function rmDir(dirPath) {
  13. let entries = fs.readdirSync(dirPath);
  14. if (entries.length > 0) {
  15. for (var i = 0; i < entries.length; i++) {
  16. var filePath = path.join(dirPath, entries[i]);
  17. if (fs.statSync(filePath).isFile()) {
  18. fs.unlinkSync(filePath);
  19. } else {
  20. rmDir(filePath);
  21. }
  22. }
  23. }
  24. fs.rmdirSync(dirPath);
  25. }