1

I am reading some strings from a batch file and trying to append them all, separated by a space. Here is the code

for /F %%x in (C:\dir_1\deploy_build\apps.properties) do (
            set warFiles=%%x%warFiles%
        )
echo %warFiles%

if the content of the properties file is

sz1056
warFile1
warFile2

the output I am getting is warFile2 but the output that i am expecting is sz1056 warFile1 warFile2 How can I do this?

1
  • You need delayed variable substitution here, else %%x%warFiles% uses the current value of x and the old (from before the loop started) value of warFiles Commented Aug 3, 2016 at 14:24

1 Answer 1

1

you need delayed expansion:

setlocal enableDelayedExpansion
for /F %%x in (C:\dir_1\deploy_build\apps.properties) do (
            set "warFiles=%%x !warFiles!"
        )
echo %warFiles%
Sign up to request clarification or add additional context in comments.

4 Comments

its working but I am not getting the expected output yet, this is the output I am getting warFile2 warFile1 sz1056 warFile2warFile2
@viveksinghggits and is the issue now?
my bad, the output is correct but the sequence is not. I am expecting sz1056 warFile1 warFile2 but getting warFile2 warFile1 sz1056 as output.
@viveksinghggits because I used your logic. change the set line to set "warFiles=!warFiles! %%x"

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.