Trying to search filenames with special characters in windows explorer (Windows 10)

2

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?

Sia

Posted 2017-07-14T23:34:53.787

Reputation: 23

So are you looking for a Windows Explorer solution only or would a script solution be sufficient as well? – Pimp Juice IT – 2017-07-15T02:09:58.880

Answers

4

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

Use the following search expression:

name:~"*(2)*"

Notes:

  • ~ 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:

Before:

enter image description here

After:

enter image description here


Further Reading

DavidPostill

Posted 2017-07-14T23:34:53.787

Reputation: 118 938

@Sia Do you need more help? If this answered your question, please don't forget to accept the answer.

– DavidPostill – 2017-07-16T10:34:26.277

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 – 2017-07-17T11:19:35.923

0

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
}
PopD

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 
}
PopD

LotPings

Posted 2017-07-14T23:34:53.787

Reputation: 6 150

Why use a complicated PowerShell script when you can do it easily using the Explorer Search functionality? – DavidPostill – 2017-07-15T12:27:17.530

@DavidPostill because of additional functionality? It does ashure to only delete binary equal files. – LotPings – 2017-07-15T12:31:22.137

OK. But that's not what the question asked for :) – DavidPostill – 2017-07-15T12:32:29.737

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 – 2017-07-16T09:34:41.850