Powershell How To Removve Only Empty Direcoties

[Solved] Powershell How To Removve Only Empty Direcoties | Basic - Code Explorer | yomemimo.com
Question : powershell how to removve only empty direcoties

Answered by : im-just-blue

# A script block (anonymous function) that will remove empty folders
# under a root folder, using tail-recursion to ensure that it only
# walks the folder tree once. -Force is used to be able to process
# hidden files/folders as well.
$tailRecursion = { param( $Path ) foreach ($childDirectory in Get-ChildItem -Force -LiteralPath $Path -Directory) { & $tailRecursion -Path $childDirectory.FullName } $currentChildren = Get-ChildItem -Force -LiteralPath $Path $isEmpty = $currentChildren -eq $null if ($isEmpty) { Write-Verbose "Removing empty folder at path '${Path}'." -Verbose Remove-Item -Force -LiteralPath $Path }
}

Source : https://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell | Last Update : Fri, 04 Dec 20

Answers related to powershell how to removve only empty direcoties

Code Explorer Popular Question For Basic