Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to read single lines from a text file and store each line in a variable so that I can use that variable to do something (such as COPY, RENAME, MOVE, etc). Here is the operation I want:
1) Read 1st line from txt
1) Store that line in a variable so that I can do something with it (e.g. COPY)
2) Read 2nd line from txt
2) Store that line in the same variable (overwriting the previous info)
2) Run command using that var
3) Read 3rd line from txt
3) Store that line in the variable
...and so on.Is this possible in Windows XP DOS? If so, how can it be done? My guess is a FOR loop is involved but I'm not sure after that.
(I posted this in WinXP forum but I don't know why they deleted it, maybe this is the right place)

::==
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in (myfile) do (
echo do my commands on %%a
)
::==
=====================================
If at first you don't succeed, you're about average.M2

I think that just outputs the entire text file to the screen at once. I'm trying to do it line-by-line. Doesn't look like there's a way to stop it after each line.

As per Mechanix script with a pause. That will cause a stop after every line
for /f "tokens=* delims= " %%a in (myfile) do (
echo do my commands on %%a
pause
)

What I want to do is to be able to store every line in a variable and USE that variable after every line. I'm not trying to read the file, I know what's in it. I want to use the data from the file (in a variable) to perform file management operations.

::==
:: gets lines into vars c1 v2 v...@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in (myfile) do (
set /a n+=1
set v!n!=%%a
)
set v
::==
=====================================
If at first you don't succeed, you're about average.M2

I'm looking for something very similar to this, but insteady, I only need one line to set one system variable.
-locate first line in Temp.txt
-Set %CLIENTNAME% per that line in Temp.txtTried some mods to the code above, but couldn't get it.
Your response is appreciated!
PM

::==
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in (myfile) do (
if !myvar!'==' set myvar=%%a
)
echo myvar is set to !myvar!
::==
=====================================
If at first you don't succeed, you're about average.M2

![]() |
line pattern perl program...
|
vb.net DataGridView quest...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |