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?
If specific text found in file, del file
Moderator: DosItHelp
Re: If specific text found in file, del file
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
or
findstr /r /c:"[Aa] [Ss]pecific [Tt]ext" file.txt && del file.txt /q
findstr can use regular expressions
-
- Posts: 16
- Joined: 29 Jan 2010 17:19
Re: If specific text found in file, del file
could you do *.* instead of file.txt? would that work?I'ma go find out.
Re: If specific text found in file, del file
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