Categories:
  🠪  General

Email
  🠪  Servers
  🠪  Testing
  🠪  Tips

Hardware
  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  Tablets
  🠪  Testing
  🠪  Virtualization

hidden
  🠪  General

Links
  🠪  Interesting
  🠪  Media

Network
  🠪  Data
  🠪  Testing
  🠪  VPN

Scripts
  🠪  Batch
  🠪  Linux
  🠪  Powershell

Servers
  🠪  Databases
  🠪  Misc
  🠪  Website

Software
  🠪  Other

Utilities
  🠪  Backup
  🠪  Fix Issues
  🠪  Recovery

Video
  🠪  Editing

Websites
  🠪  HTML
  🠪  Testing

Windows
  🠪  Adjustments
  🠪  Issues
  🠪  Remote Desktop
  🠪  Security
  🠪  Slow
  🠪  Software
  🠪  Startup

Submit Entry
Airin's Notes

Category: Scripts 🠪 Powershell
Delete duplicate files found with a suffix like (Copy)
November 29, 2023

$Folder = "E:\Recovered_Files"
$ScanSubfolders = $false

$SuffixForDuplicate = " - Copy"

$Files = get-childitem $Folder
$DeletedCount = 0

foreach ( $File in $Files ){
$MatchName = "$($File.BaseName)$($SuffixForDuplicate)$($File.Extension)"
$Match = $Files | Where-Object { $_.Name -eq $MatchName -and $_.Length -eq $File.Length }
if ( $Match.count -gt 0 ){
#Duplicate found!
write-host "Deleting $($Match.FullName)"
Remove-Item $Match.FullName -Force
$DeletedCount++
}
}

Write-Host "Deleted a total of $($DeletedCount) file(s)."





This site is meant to be used as a reference for myself, although others may find it useful. I use it to keep track of certain fixes, software, and other solutions which I may need while assisting customers. The page layout is pure HTML/CSS and is kept simple to optimize loading time and fast results.

Return to Airin's Computers