Skip to content

Instantly share code, notes, and snippets.

@umer936
Created August 28, 2023 23:42
Show Gist options
  • Save umer936/f0bf66b80fd9a05aa35932237cb8fa99 to your computer and use it in GitHub Desktop.
Save umer936/f0bf66b80fd9a05aa35932237cb8fa99 to your computer and use it in GitHub Desktop.
Powershell empty/duplicate finder/remover
ls *.* -recurse | get-filehash | group -property hash | where { $_.count -gt 1 } | % { $_.group | select -skip 1 } | del
# https://n3wjack.net/2015/04/06/find-and-delete-duplicate-files-with-just-powershell/
$tdc="C:\a\c\d"
do {
$dirs = gci $tdc -directory -recurse | Where { (gci $_.fullName -Force).count -eq 0 } | select -expandproperty FullName
$dirs | Foreach-Object { Remove-Item $_ }
} while ($dirs.count -gt 0)
# https://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment