Delete a non-empty directory - Node.js File

Node.js examples for File:Directory

Description

Delete a non-empty directory

Demo Code


var exec = require('child_process').exec;

/**/*  www  .  j a v  a2s . co m*/
 * Delete a non-empty directory.
 * @param {String} path path of the directory to delete.
 * @returns {Promise}
 */
module.exports = function(path) {
  return new Promise((resolve, reject) => {
    exec(`rm -rf "${path}"`, function(err, stdout, stderr) {
      if (err) reject(err);
      else resolve();
    });
  }); 
};

Related Tutorials