Skip to content

Instantly share code, notes, and snippets.

@valueforvalue
Last active April 7, 2026 20:30
Show Gist options
  • Select an option

  • Save valueforvalue/7c9ce611f1247eee0a1931699a565576 to your computer and use it in GitHub Desktop.

Select an option

Save valueforvalue/7c9ce611f1247eee0a1931699a565576 to your computer and use it in GitHub Desktop.
Powershell snippet to Delete duplicates by filename NO WARNING
# 1. First, remove the browser-renamed copies (e.g., "File (1).pdf")
Get-ChildItem -Filter "*(*).pdf" -Recurse | ForEach-Object {
$originalName = $_.Name -replace "\s\(\d+\)", ""
if (Test-Path "$($_.DirectoryName)\$originalName") {
Remove-Item $_.FullName -Force
}
}
# 2. Then, remove any remaining exact name duplicates across different folders
Get-ChildItem -Filter *.pdf -Recurse | Group-Object Name | Where-Object {$_.Count -gt 1} | ForEach-Object {
$_.Group | Select-Object -Skip 1 | Remove-Item -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment