Copy to Clipboard
$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)."
|