Solved

Probelm with the FOR command in XP

Posted on 2004-08-23
2
371 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

759 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