copy txt file - only copies 1/3 of the file - what happened?

M

Mmcolli00 Mom

File.open('oldFile.txt', 'r') do |f1| #file contains XML type data
m = f1.gets
File.open('newFile.txt','w') do |f2| #newFile to separate data in
oldFile
f2.puts m.split("<")
end
end

Hello All.
There is something that I did that was weird here. I say this because
when I open the new file that it creates its 1/3 the size of the
original. It seems to just completely cut off. I took off the .split and
it still did this, so I know it has nothing to do with split. What do
you think is going on?

oldFile.txt
contains XML formatted data.

newFile.txt
is supposed to break each line up what starts with < giving a new line
per element for later use.
 
M

Matthew Moss

File.open('oldFile.txt', 'r') do |f1| #file contains XML type data
m = f1.gets
File.open('newFile.txt','w') do |f2| #newFile to separate data in
oldFile
f2.puts m.split("<")
end
end


Perhaps replace line 2 with:

m = f1.read

?
 
B

botp

File.open('oldFile.txt', 'r') do |f1| #file contains XML type data
m = f1.gets

ok, this gets just one line of text fr f1
File.open('newFile.txt','w') do |f2| #newFile to separate data in
oldFile
f2.puts m.split("<")

and you placed that one line on f2

and that is all. you just copied one line.

hint: File.open by itself does not loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top