2022-02-14 01:39:33 +00:00
|
|
|
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 {
|
2022-06-27 06:21:04 +00:00
|
|
|
await fsPromises.rm(dirPath, { recursive: true, force: true});
|
2022-02-14 01:39:33 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|