Solved how to transfer variable data in for loop?

November 1, 2011 at 07:55:39
Specs: Windows 7, 2.66 GHZ
for /f "tokens=*" %%v in (file.txt) do ( echo %%v )

this command displays each line of the file "file.txt"

How to save the data in %%v to another variable in for loop..???

for /f "tokens=*" %%v in (file.txt) do ( set string=%%v & echo %string% )

in the above command the output is JUST ECHO OFF.. I don't get the lines of file.txt as output...!!

HOW TO rectify the error in my coding...???
I want to transfer the data of first line in %%V to %string% inside the for loop......??


See More: how to transfer variable data in for loop?

Report •


#1
November 1, 2011 at 14:40:35
for /f "tokens=*" %%v in (file.txt) do (
set string=%%v
echo %string%
)

Report •

#2
November 1, 2011 at 18:04:14
✔ Best Answer
Delayed expansion must be enabled in order to expand an environment variable within a For loop.

@echo off
cls
setlocal enabledelayedexpansion

for /f "tokens=*" %%v in (file.txt) do  (set string=%%v & echo !string!)


Please come back & tell us if your problem is resolved.


Report •

#3
November 5, 2011 at 09:23:30
Thankx dude it's working...!! Thanks a lot..!!!!!

Report •

Related Solutions


Ask Question