PoshCode Archive  Artifact [3d7e54723a]

Artifact 3d7e54723a87c536779cc90f4fb23d08a57fb2cf7cde91c5b0d8778757b59304:

  • File Delete-Empty-Folders.ps1 — part of check-in [38ca4d8c4e] at 2018-06-10 13:55:37 on branch trunk — 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. (user: Trevor Wilson size: 899)

# 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!"