Mr_Fish
Mr_Fish

Reputation: 79

Bat file to delete all files with a specific string within?

Guys I am trying to write a batch file that kills all files within a directory - basically every file will have 'status' within it

I cant just kill the files on file extension either - there is this post batch script delete file containining certain chars however, this does not seem to do it

Upvotes: 4

Views: 3890

Answers (1)

MC ND
MC ND

Reputation: 70971

for /f "delims=" %%a in (' 
    findstr /l /i /m /c:"status" "c:\somewhere\*.*"
') do echo del "%%a"

This uses findstr to list the files (/m) containing the literal (/l) "status" ignoring the string case (/i). The list is processed with a for /f command to execute the del operation for each file.

del commands are only echoed to console. If the output is correct, remove the echo command.

edited if the string status is not inside the file but in the file name, the code is reduced to

del "c:\somewhere\*status*"

Upvotes: 2

Related Questions