projeto-hit/TEST_SERVER1/whats/helpers/remove_dir.js

28 lines
613 B
JavaScript

const fsPromises = require("fs/promises");
const fs = require('fs')
// Delete a directory and its children
const removeDir = async (dirPath) => {
if (fs.existsSync(dirPath)) {
try {
await fsPromises.rm(dirPath, { recursive: true, force: true });
console.log("Directory removed!");
return true
}
catch (err) {
console.log('An error occurred while removing the directory: ', err);
}
}
else {
console.log('Directory not found to remove: ', dirPath)
}
return false
}
module.exports = removeDir ;