24 lines
673 B
TypeScript
24 lines
673 B
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
|
|
export default function emptyDirectory(dir: string) {
|
|
try {
|
|
const dirContent = fs.readdirSync(dir);
|
|
|
|
for (let i = 0; i < dirContent.length; i++) {
|
|
const fileFolder = dirContent[i];
|
|
const fullFileFolderPath = path.join(dir, fileFolder);
|
|
const stat = fs.statSync(fullFileFolderPath);
|
|
|
|
if (stat.isDirectory()) {
|
|
emptyDirectory(fullFileFolderPath);
|
|
continue;
|
|
}
|
|
|
|
fs.unlinkSync(fullFileFolderPath);
|
|
}
|
|
} catch (error: any) {
|
|
console.log(`Error Emptying ${dir}: ${error.message}`);
|
|
}
|
|
}
|