1

I have to read contents from a file. In this case, Files.txt. The script is as below:

@echo off
setlocal EnableDelayedExpansion
REM for /F "delims=" %%b in (Files.txt) do @set str1=%%b
REM set str1=bcd
for /F "delims=" %%a in (Files.txt) do (
    set str1=%%a
    if not x%str1:bcd=%==x%str1% (
        echo OK
    ) else (
        echo Not OK
    )
)
endlocal

When I assign value of str1 manually, it executes fine but while taking from file which contains multiple values like aer,bcd,123 etc. It fails.

Am I doing any mistake in this script?

1

1 Answer 1

1

There are many ways to solve - Based on what I have done before - I tend to make sure I break things up. - http://www.robvanderwoude.com/ has a great site on Batch files. I would make sure you use tokens which will get you where you want to go i.e. columns of data

FOR /F "tokens=1,2 delims=," %%G IN (Files.txt) DO call:WORK %%G %%H

:WORK
SET aer=%1
SET bcd=%2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.