Solved

Probelm with the FOR command in XP

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dividesSelf challange 15 81
for loop with Set 4 46
Tviruailstringtree sort multi columns on header click 1 34
Path to Python 9 46
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

19 Experts available now in Live!

Get 1:1 Help Now