Finding files with parenthesis in the name using Windows Explorer Search (and PowerShell)

Today I had a friend message me and ask how he can find all files that have the text (1) or (2) or (3) in the file name using Windows Explorer as he wanted to delete them. First up I must admit to thinking it was a silly question, after all…just type it into the search box right? Wrong, Windows Explorer won’t match on those parenthesis…that was something that I did not know as I really don’t use it all that often.

So I tried it to confirm his findings.

I created a folder called “New Folder” with the following named text files inside.

Folder 1

 

 

 

 

 

 

 

 

And just to test searching inside sub folders, I created another folder with the following single file inside.

Folder 2

 

 

 

 

 

 

 

Then, using the “Search This PC” box in Windows 10,

Search This PC

 

 

 

 

 

 

 

 

 

 

I typed in (1) as you’d expect.

(1)

 

 

Here are the results of that search.

Flawed Results 2

 

 

 

 

 

 

 

It’s correctly found 3 of the files that contain (1) in the filename, but it’s also returned the filename called 1 yet this does not match…so it appears those parenthesis are being ignored and its simply matching on the number 1 alone. Well that’s not what I want, I want it to include those parenthesis.

I wondered if it would require quotes.

“(1)”

Nope the result was the same.

However it turns out, this was the answer:

name:(~=”(1)”)

One day I might get around to taking a closer look at search options in Windows Explorer, but I probably would have used Windows PowerShell to do this anyway

Get-ChildItem -recurse | ? {$_.Name -like “*(1)*”}

And if you are certain you want to delete them, just pipe this into the “Remove-Item” cmdlet.

Get-ChildItem -recurse | ? {$_.Name -like “*(1)*”} | Remove-Item

And they’re gone.

Anyway, my friends happy and I learnt something today. Hope it helps you.

 
Comments

No comments yet.

Leave a Reply