# how to concatenate strings with the lines of a text file



## victorxbox1980 (Sep 14, 2012)

Hello

I've been trying to concatenate strings with the lines of a text file, but something is wrong with my code and I belive is the agruments I am using in the the For cycle. If any one can help me I'll much appreciate it.

My code is:


```
@echo off
set "input=C:\Users\123\Desktop\List.txt"
for /f "usebackq tokens=*" %%F in ("%input%") do (
        set "str1=C:\some directory\"
	set "str2=%%~F"
	set "str3=.pdf"
	set "str4=%str1%%str2%%str3%"
	echo.%str4%
)
```
and the text file is something like:


```
121122
122233
123344
124455
```
But I am only getting a wrong answer and I have to run it like 3 times to get a real result and it's wrong, the first two are blank spaces and the third one gives back the last line in the text file but repeated n times where, n is the number of lines in the text file.

Result:


```
C:\Users\123\Desktop>concatenate.bat





C:\Users\123\Desktop>concatenate.bat





C:\Users\123\Desktop>concatenate.bat
C:\some directory\124455.pdf
C:\some directory\124455.pdf
C:\some directory\124455.pdf
C:\some directory\124455.pdf
C:\some directory\124455.pdf

C:\Users\123\Desktop>
```
So, if any one has a clue on what is wrong please let me know.

Regards

-Victor-


----------



## Squashman (Apr 4, 2003)

Setlocal enabledelayedexpansion
Use exclamations with you variable names instead of percent symbols.


----------

