添加 delete_empty_folder.ps1
This commit is contained in:
20
delete_empty_folder.ps1
Normal file
20
delete_empty_folder.ps1
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user