0

I'm trying to loop through a text file found during a wildcard search and append each line as its own portion of a string.

My file has the two lines:

Load.SQL.Sample.Basic.Data
Script.Calc.Sample.Basic.AggAll

I want to loop through them and aggregate them into one variable. At each step I want it to echo what's in the variable:

Load.Sql.Sample.Basic.Data
Load.Sql.Sample.Basic.Data Script.Calc.Sample.Basic.AggAll

This script just replicates the input file:

set JOBLIST=
FOR %%i in (*.Job.txt) DO (
    FOR /F %%a in (%%i) DO (
        SETLOCAL EnableDelayedExpansion
        set JOBLIST=!JOBLIST! %%a
        echo !JOBLIST!>>Test.txt
        ENDLOCAL
    )
)

This is the output (each line has a leading space):

 Load.SQL.Sample.Basic.Data
 Script.Calc.Sample.Basic.AggAll

1 Answer 1

1

Had the delayed expansion in the wrong place:

SETLOCAL EnableDelayedExpansion
FOR %%i in (*.Job.txt) DO (
    FOR /F %%a in (%%i) DO (
        set JOBLIST=!JOBLIST! %%a
        echo !JOBLIST!>>Test.txt        
    )
)
ENDLOCAL
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.