IF EXIST [string in file] THEN [command]
Moderator: DosItHelp
-
- Posts: 82
- Joined: 24 Apr 2011 19:20
IF EXIST [string in file] THEN [command]
I'm making a batch file that will add a string to a file of it doesn't exist in that file. Is this possible?
Re: IF EXIST [string in file] THEN [command]
Code: Select all
findstr /c:"hello world" a.txt || echo hello world >>a.txt
Re: IF EXIST [string in file] THEN [command]
The above works, but you probably don't want to see the FINDSTR output if the string already exists. So we just redirect output to NUL:
Dave Benham
Code: Select all
findstr /c:"hello world" a.txt >nul || echo hello world >>a.txt
Dave Benham