Page 1 of 1
If specific text found in file, del file
Posted: 23 Feb 2010 20:54
by BAT Beginner
I need a code that would detect a specific text in a file, and if that text is found, it be deleted.
Would anyone happen to know such a code?
Re: If specific text found in file, del file
Posted: 24 Feb 2010 04:17
by !k
find /i "a specific text" file.txt && del file.txt /q
or
findstr /r /c:"[Aa] [Ss]pecific [Tt]ext" file.txt && del file.txt /q
findstr can use regular expressions
Re: If specific text found in file, del file
Posted: 24 Feb 2010 16:23
by BAT Beginner
could you do *.* instead of file.txt? would that work?I'ma go find out.
Re: If specific text found in file, del file
Posted: 25 Feb 2010 02:11
by !k
Code: Select all
for /f "delims=" %%f in ('findstr /m /c:"a specific text" "d:\path\*.txt"') do del "%%~ff"
Sure to use the path or extension, because this code also contains a "a specific text" and the batch file will erase itself