powershell get empty folders
Get-ChildItem "C:\Scripts" -Recurse -Directory | Where-Object {!$_.GetFileSystemInfos().Count} | Select-Object FullName
Source: superuser.com
powershell delete folder
Remove-Item 'D:\temp\Test Folder1'
powershell how to removve only empty direcoties
# 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: stackoverflow.com
powershell delete empty folders
$tdc="C:\a\c\d" $dirs = gci $tdc -directory -recurse | Where { (gci $_.fullName).count -eq 0 } | select -expandproperty FullName $dirs | Foreach-Object { Remove-Item $_ }
Source: stackoverflow.com