Files
delete_empty_folder/delete_empty_folder.ps1
2025-07-01 16:47:49 -04:00

21 lines
630 B
PowerShell

param (
[string]$Path = $(Read-Host "Scan path")
)
if (!(Test-Path $Path)) {
Write-Host "Error: Path not exist" -ForegroundColor Red
exit
}
$EmptyFolders = Get-ChildItem -Path $Path -Recurse -Directory | Where-Object { @(Get-ChildItem -Path $_.FullName).Count -eq 0 }
if ($EmptyFolders.Count -eq 0) {
Write-Host "no empty folders found" -ForegroundColor Green
} else {
foreach ($folder in $EmptyFolders) {
Write-Host "Deleted: $($folder.FullName)" -ForegroundColor Yellow
Remove-Item -Force -Recurse $folder.FullName
}
Write-Host "All empty folders deleted" -ForegroundColor Green
}