FatalBulletHit

Empty Folder Remover (Simple)

Apr 13th, 2019 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://pastebin.com/fmBzGg2W
  2. # Check out this pastebin entry for a more advanced version: https://pastebin.com/mRhrVdGA
  3.  
  4. $Host.UI.RawUI.WindowTitle = 'Empty Folder Remover (Simple)'
  5. $Target = 'C:\Target'
  6.  
  7. Get-ChildItem -LiteralPath $Target -Recurse -Force -Directory -ErrorAction Ignore | Where-Object {(Get-ChildItem -LiteralPath $_.FullName -Recurse -Force -File | Select-Object -First 1).Count -eq 0} | ForEach-Object {
  8.  
  9.     Remove-Item -LiteralPath $_.FullName -Recurse -Force -ErrorAction Ignore
  10.     "Removed '{0}'" -f $_.FullName
  11.        
  12. }
Add Comment
Please, Sign In to add comment