Kenneh
Kenneh

Reputation: 1

Create batch file to find string in txt files and then delete the txt file

I'm looking for the correct syntax to make a batch file that finds a word in txt files and then deletes all the txt files with that word in it.

I've been using findstr to get the results but how do I manage to delete the files after that?

findstr -m "string" *txt | del

doesn't work

Should I use a variable or something? Thanks for the help

Upvotes: 0

Views: 99

Answers (1)

npocmaka
npocmaka

Reputation: 57242

If you dont't need recursive search you can try like this:

for %%a in (*txt) do (
   find /i "string" "%%~fa" >nul 2>nul &&(
      del /q /f "%%~fa"
   )
)

Upvotes: 1

Related Questions