const fs = require('fs').promises;
const path = require('path');
async function deleteFolderRecursive(folderPath) {
try {
const files = await fs.readdir(folderPath);
for (const file of files) {
const filePath = path.join(folderPath, file);
const stats = await fs.stat(filePath);
if (stats.isDirectory()) {
await deleteFolderRecursive(filePath);
} else {
await fs.unlink(filePath);
}
}
await fs.rmdir(folderPath);
} catch (err) {
console.error(`Error deleting folder: ${folderPath}`, err);
}
}
// Example usage:
const folderPathToDelete = '/path/to/your/folder';
deleteFolderRecursive(folderPathToDelete);