I have a batch file as follows;
CD C:\MyFolder
findstr /c:"stringToCheck" fileToCheck.bat
IF NOT XCOPY "C:\OtherFolder\fileToCheck.bat" "C:\MyFolder" /s /y
I am getting an error (“C:\OtherFolder\fileToCheck.bat” was unexpected at this time.) when trying to execute this.
Please let me know what I am doing wrong.
You are not evaluating a condition for the IF. I am guessing you want to not copy if you find stringToCheck in fileToCheck. You need to do something like (code untested but you get the idea):
EDIT by dbenham
The above test is WRONG, it always evaluates to FALSE.
The correct test is
IF ERRORLEVEL 1 XCOPY ...Update: I can’t test the code, but I am not sure what return value findstr actually returns if it doesn’t find anything. You might have to do something like: