Exception when writing to a file

Why does this work:

docname = 'dir/file.gz’
Net::HTTP::Proxy(proxy_addr, proxy_port).start(site) { |http|
response = http.get(base + docname)
File.open(File.join(File.dirname(FILE), docname), “wb+”) { |f|
f.write(response.body) }
}

But this doesn’t:

docs = File.readlines( File.join(File.dirname(FILE),
“doclist.txt”) )

Net::HTTP::Proxy(proxy_addr, proxy_port).start(site) { |http|
docs.each { |docname|
response = http.get(base + docname)
File.open(File.join(File.dirname(FILE), docname), “wb+”) { |f|
f.write(response.body) }
}
}

Fails with:
c:/MyTools/getdocs.rb:16:in initialize': Invalid argument - c:/MyTools/dir/file.gz (Errno::EINVAL) from c:/MyTools/getdocs.rb:16:inopen’
from c:/MyTools/getdocs.rb:16
from c:/MyTools/getdocs.rb:13:in start' from c:/langs/ruby/lib/ruby/1.8/net/http.rb:324:instart’
from c:/MyTools/getdocs.rb:13
from c:/MyTools/getdocs.rb:12:in `each’
from c:/MyTools/getdocs.rb:12

All the subdirectories exist. It obviously can get and write the file
(as the first example shows). The only difference is the 'docs.each’
loop. The docs variable is initialized propererly with the list of files
(I’ve checked).

Anyone?

Cheers,
Assaph

Mehr, Assaph (Assaph) wrote:

But this doesn’t:

docs = File.readlines( File.join(File.dirname(FILE),
“doclist.txt”) )

Does your lines in docs contain the trailing newlines from doclist.txt?
Perhaps that is what the call to File.open doesn’t like.

···


([ Kent Dahl ]/)_ ~ [ Kent Dahl - Kent Dahl ]/~
))_student_/(( _d L b_/ Master of Science in Technology )
( __õ|õ// ) ) Industrial economics and technology management (
_
/ö____/ (_engineering.discipline=Computer::Technology)