Advertisement
FatalBulletHit

Duplicate File Remover

Mar 11th, 2018 (edited)
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://pastebin.com/Qq43NRQF
  2. # PowerShell solution to remove duplicate files
  3.  
  4. $target = "C:\adjust\path"
  5.  
  6. $Host.UI.RawUI.WindowTitle = 'Duplicate File Remover'
  7. $start = (Get-Date)
  8. $i = 0
  9.  
  10. $file_list = New-Object System.Collections.ArrayList
  11.  
  12. (Get-ChildItem -Path $target -File -Recurse) | ForEach-Object {
  13.  
  14.     $hash = (Get-FileHash $_.FullName).Hash
  15.  
  16.     if ($file_list.Contains($hash) {
  17.  
  18.         Remove-Item $_.FullName
  19.         Write-Host Removed duplicate: $_.FullName
  20.         $i++
  21.  
  22.     } else {
  23.  
  24.         $file_list.Add($hash) > $null
  25.  
  26.     }
  27. }
  28.  
  29. Write-Host "`n`n`nRemoved $i duplicate(s)!`nDuration: "((Get-Date) - $start).ToString("hh\:mm\:ss\.fff")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement