Skip to content

Instantly share code, notes, and snippets.

@Wendelstein7
Created January 29, 2021 10:08
Show Gist options
  • Save Wendelstein7/0aeb7db600e3cdc07230bd4fe8091e24 to your computer and use it in GitHub Desktop.
Save Wendelstein7/0aeb7db600e3cdc07230bd4fe8091e24 to your computer and use it in GitHub Desktop.
Powershell script to delete all empty subdirectories
# Powershell script to delete all empty subdirectories
$rootPath = Get-Location
foreach($childItem in (Get-ChildItem $rootPath -Recurse))
{
# if it's a folder AND does not have child items of its own
if( ($childItem.PSIsContainer) -and (!(Get-ChildItem -Recurse -Path $childItem.FullName)))
{
# Delete it
Remove-Item $childItem.FullName -Confirm:$false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment