Last active
April 7, 2026 20:30
-
-
Save valueforvalue/7c9ce611f1247eee0a1931699a565576 to your computer and use it in GitHub Desktop.
Powershell snippet to Delete duplicates by filename NO WARNING
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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