# encoding: ascii
# api: powershell
# title: Delete Empty Folders
# description: This is a script to remove empty folders from a drive. I used it when i had to clear up a shared drive from a former company.
# version: 0.1
# author: Trevor Wilson
# license: CC0
# x-poshcode-id: 5467
# x-archived: 2016-06-06T19:17:31
# x-published: 2016-09-25T18:54:00
#
# Please let me know if you know a way i can improve it.
# Nice script. I added a check to exclude folders with one or more subfolders but have no files.
#
$Drive = Read-Host "Path to Folders"
Write-Host "This will delete all empty folders in this directory!"
$a = Get-ChildItem $drive -recurse | Where-Object {$_.PSIsContainer -eq $True}
$a | Where-Object {($_.GetFiles().Count -lt 1 -and $_.GetDirectories().Count -lt 1)} | Select-Object FullName | ForEach-Object {remove-item $_.fullname -recurse}
Write-Host "All Done!"