Jesús Gabriel y Galán
6/9/2009 1:31:00 PM
On Tue, Jun 9, 2009 at 2:52 PM, Peter Bailey<pbailey@bna.com> wrote:
> Hi,
> In the "pickaxe" book I see how to use a "puts" to populate a file with
> data. I try the same thing, and, it works, but, it's listing the data as
> an array. How can I get separate lines for each item in the array?
> Thanks,
> Peter
>
> In the book:
> =A0File.open("output.txt", "w") do |file|
> =A0file.puts "Hello"
> =A0file.puts "1 + 2 =3D #{1+2}"
> =A0end
> =A0# Now read the file in and print its contents to STDOUT
> =A0puts File.read("output.txt")
> produces:
> =A0Hello
> =A01 + 2 =3D 3
>
> My script:
> =A0Dir.chdir("L:/png/69000")
> =A0files =3D Dir.glob("*.png")
> =A0File.open("F:/workflows/graphics/receipts/pngfiles.txt", "w") do |file=
|
> =A0file.puts "#{files}"
> =A0end
> produces:
> =A069116.png69251.png69391.pngAZ69080.pngAZ69982.pngcx69362.pngcx69363.pn=
g
Dir.glob returns an array, so two possibilities are (untested):
File.open("F:/workflows/graphics/receipts/pngfiles.txt", "w") do |file|
file.puts files.join("\n")
end
File.open("F:/workflows/graphics/receipts/pngfiles.txt", "w") do |file|
files.each {|f| file.puts f }
end
Hope this helps,
Jesus.