How to delete files with specified text in their names?

I have a folder on my computer in which I have a lot of .jpg files. I want to filter out all files that have a specific part in their name, for example:

We have a folder which contains files A.jpg, B.jpg, C_bad.jpg, D_bad.jpg, etc.

I want to delete every file that has "_bad" in its name. Is something like this even possible? Or do I have to delete all these files manually?


I want to filter out all files that have a specific part in their name

You can do this with wildcards.


From a command line

To display matching files:

dir *_bad.jpg

To delete matching files:

del *_bad.jpg

Use the /s option to match files in subdirectories as well as the current directory.


From Explorer

To display matching files:

  • enter *_bad.jpg in the search box

To delete matching files:

  • enter *_bad.jpg in the search box, select the results and press Delete or Del

Further reading

wildcards


You can do this easilly using PowerShell :

Get-Childitem -path c:\path -Filter *.jpg -Recurse | where-object {$_.Name -ilike "*_bad*"} | Remove-Item -Force -WhatIf

This little script will delete every JPG files located under c:\path (and subfolders), containing "_bad" in their name.

Simply change the root path to match your needs. The -whatif parameter used at the end of the script permits to see what files will be deleted. Remove this switch when your are ready to delete them.

Hope this helps !