|
Answer» i K now this is PROBABLY really n00b, but i was wondering how to search for a word inside a .txt document, using the if command. so far i have:
@ECHO OFF IF NOT adam==test.txt del "test.txt" pause
it works if the document only CONTAINS the word adam. i was wondeing if you could help me in finding a command that searches for the word not just COMPARES it. yes i have tried using findstr like,
@ECHO OFF IF NOT findstr adam command del "test.txt" pause
:exclamationbut then it desnt workYou were close in your example; you should check ErrorLevel after your FindStr
@ECHO OFF findstr adam command IF ErrorLevel 1 del "test.txt" pause
If the text is found, errorlevel is set to 0, otherwise it is greater than 0 - 1 means not found Grahamoh ok, thanks. i didnt really understand errorlevel so i was trying to stay away from iti tried that but it didnt work, so i changed it a but and came up with this
@ECHO OFF findstr /i /c:adam "test.txt" IF ErrorLevel 1 del "test.txt" pause
this one works, if you want the text to be case SENSITIVE you dont put the /i
|