Solved

Probelm with the FOR command in XP

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now