Powershell Obtenha pastas vazias
Get-ChildItem "C:\Scripts" -Recurse -Directory | Where-Object {!$_.GetFileSystemInfos().Count} | Select-Object FullName
Troubled Toad
Get-ChildItem "C:\Scripts" -Recurse -Directory | Where-Object {!$_.GetFileSystemInfos().Count} | Select-Object FullName
Remove-Item 'D:\temp\Test Folder1'
# 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
}
}
$tdc="C:\a\c\d"
$dirs = gci $tdc -directory -recurse | Where { (gci $_.fullName).count -eq 0 } | select -expandproperty FullName
$dirs | Foreach-Object { Remove-Item $_ }