Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Probelm with the FOR command in XP

Posted on 2004-08-23
2
Medium Priority
?
389 Views
Last Modified: 2010-04-17
Hi all,

I am trying to output the contents of a text file to another file whilst putting a coomand in fornt.

I have a text file called test.txt which contains file names and locations of all files with the attribute of A, it is desplayed like this

c:\test.txt
c:\program files\test folder\test.bat

when I use the for command as below it seems to chop of some of the words in the line, so for example with the word hello inserted before the file names this is how the 2 would come out

hello c:\test.txt
hello c:\program

here is what i am using
for /f %I in (c:\test.txt) do @echo hello %I >>c:\test2.txt

I am a little new to this and have gone by what i understand to date so could anyone please explain their answer clearly so I can make head and tail of it

Many thanks

Glenn
0
Comment
Question by:perfectpc
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 2000 total points
ID: 11870937
The problem is that the FOR command is parsing each line of the file with blanks and tabs as delimiters. So it sees the second line as having three tokens:

c:\program
files\test
folder\test.bat

You can avoid this behaviour by specifying a different delimiter set:

for /f "delims=," %I in (c:\test.txt) do @echo hello %I >>c:\test2.txt

The delims parameter is now specifying a comma as delimiter, which doesn't appear on any of the lines, and so the whole lines will be taken as a token.
0
 
LVL 3

Author Comment

by:perfectpc
ID: 11871693
Great answer, worked first time many thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Loops Section Overview

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question