Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Probelm with the FOR command in XP

Posted on 2004-08-23
2
Medium Priority
?
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

722 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