Created
January 29, 2021 10:08
-
-
Save Wendelstein7/0aeb7db600e3cdc07230bd4fe8091e24 to your computer and use it in GitHub Desktop.
Powershell script to delete all empty subdirectories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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