添加 delete_empty_folder.ps1

This commit is contained in:
Julian
2025-07-01 16:47:49 -04:00
commit c899f99f4a

20
delete_empty_folder.ps1 Normal file
View File

@@ -0,0 +1,20 @@
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
}