projeto-hit/backend/src/helpers/DeleteDirectory.ts

24 lines
566 B
TypeScript
Raw Normal View History

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