Through a very annoying person's mistake, thousands of my files have been copied, often multiple times. This has resulted in thousands of files named filename(2), filename(3), etc.

My bright idea was to do a search for (2) and delete all the results, but the search keeps showing up all files that have the number 2 in the filename, instead of including the brackets.

I've tried name:~=(2), "(2)" and even "(2)""(2)" after searching for solutions elsewhere. None of them worked. I want to exclude files that just have a 2 in the filename, I ONLY want the files that have the two inside the brackets.

Can anyone help, please?

  • So are you looking for a Windows Explorer solution only or would a script solution be sufficient as well? – Pillsbury IT Doughboy Jul 15 '17 at 2:09

I only want the files that have the two inside the brackets (2)

Use the following search expression:



  • ~ is the literal string indicator and what follows has to match the entire file name

  • Depending on your needs filename: may be better than name:


enter image description here


enter image description here

Further Reading

  • @Sia Do you need more help? If this answered your question, please don't forget to accept the answer. – DavidPostill Jul 16 '17 at 10:34
  • No, thank you, that fixed it! This is just my first time using this site and I didn't know about accepting the answer. Ticked! – Sia Jul 17 '17 at 11:19

I suggest a PowerShell script which:

  • finds all files with a trailing (1) to the BaseName recursivly for a given starting folder.
  • Does a dir without the number to find all possible dupes and then creates a hash to only delete exact copies, asking for confirmation.
  • If files are changed in the meantime these are no more exact copies and fall through.

Change the Push-Location to fit your starting folder, save file with the extension .ps1 and execute it.

## Q:\Test\2017\07\15\SU_1230033.ps1
## inspired by http://n3wjack.net/2015/04/06/find-and-delete-duplicate-files-with-just-powershell/

Push-Location "D:\"
Get-ChildItem "* (1).*" -Recurse -File | ForEach-Object {
    $BaseFile = (Join-Path $_.Directory ($_.BaseName -replace ' ?\(\d+\)'))+"*$($_.Extension)"
    Get-ChildItem $BaseFile | Get-FileHash | Group-Object Hash |  Where { $_.Count -gt 1 } | 
        ForEach-Object {$_.Group | Select-Object -Skip 1 } | Remove-Item -Confirm

To get just a dir listing of the files use this reduced script:

Push-Location "D:\"
Get-ChildItem "* (1).*" -Recurse -File | ForEach-Object {
    $BaseFile = (Join-Path $_.Directory ($_.BaseName -replace ' ?\(\d+\)'))+"*$($_.Extension)"
    Get-ChildItem $BaseFile 
  • Why use a complicated PowerShell script when you can do it easily using the Explorer Search functionality? – DavidPostill Jul 15 '17 at 12:27
  • @DavidPostill because of additional functionality? It does ashure to only delete binary equal files. – LotPings Jul 15 '17 at 12:31
  • OK. But that's not what the question asked for :) – DavidPostill Jul 15 '17 at 12:32
  • I'm afraid I don't know how to use script at all, and David's solution worked for me. But thank you for the help! – Sia Jul 16 '17 at 9:34

In a DOS box with admin privileges, issue this, and it will move all the files (and in subdirectories) with any name and file extension that contains (2) in it and then you could just delete the target directory.

To learn more: Open a DOS command window and type: robocopy /?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.