Trying to test a string to see if it contains a substring in a Windows batch file.
This is what I have so far:
echo %1 | find "message"
if %errorlevel% == 0 echo contains string
The command line output for this is (the contents of %1 was "messages\Message.js"):
messages\Message.js contains string
The issue I am having is that the only way I can get this to work is with the exact line: echo %1 | find "js"
.
How can I do this without echoing the file path each time? When I remove the echo
, the operating system attempts to open the file. I would love to save the file path to a variable, but nothing I tried worked, I always ended up with an empty variable.
echo %1 | find "message" > NUL
if %errorlevel% == 0 echo contains string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With