PowerShell: List Empty Dir 🚀
By Xah Lee. Date: . Last updated: .
List Empty Directories
function xah-list-empty-dir {
<.DESCRIPTION
list empty dirs in current dir, recursively
.LINK
http://xahlee.info/powershell/powershell_list_empty_dir.html
.NOTES
Version: 2022-03-03 2023-08-17
.LINK
http://xahlee.info/powershell/powershell_list_empty_dir.html
dir -Directory -Recurse | Where-Object { $_.GetFileSystemInfos().Count -eq 0 }
}
Delete Empty Directories
function xah-delete-empty-dirs {
<.DESCRIPTION
delete empty dirs in current dir, recursively
.NOTES
Version: 2022-12-12 2023-08-17
.LINK
http://xahlee.info/powershell/powershell_list_empty_dir.html
$empdirs = dir -Directory -Recurse | Where-Object { $_.GetFileSystemInfos().Count -eq 0 }
Write-Host "Deleting:"
$empdirs | ForEach-Object { $_.fullname } | Out-Host
$empdirs | Remove-Item
}
PowerShell, Working with Directory