From: "Jesús Gabriel y Galán" Date: 2010-04-04T23:16:43+09:00 Subject: Re: Reading contents of all files from a Directory On Sun, Apr 4, 2010 at 3:06 PM, Hawksury Gear wrote: >> If it is only for output purposes, we can actually do it in one line: >> >> puts Dir["K:/test/*"].map {|f| File.read f} >> >> Note: this is not necessarily efficient nor safe (just think of 3GB >> files...). >> >> Kind regards >> >> robert > > Many Thanks for replying robert, I am trying to print the contents of > each file > in the following way,It isn't giving me any error message but it is not > showing any output, Could you please help. > >  arr= Dir.open("K:/test").entries >  arr.each do| file | >      File.open("file","a+") do |fd| >        fd.each {|line| print line} >        end > You have two errors there. "file" is a literal string, not the contents of the variable file. Use file without quotes. The second: http://ruby-doc.org/core/classes/IO.html Take a look at the documentation of the open modes: "a+" | Read-write, starts at end of file if file exists, | otherwise creates a new file for reading and | writing. Starts at the end of the file, so there's nothing else to read... You probably want this instead: File.open(file, "r") do |file| ... end Jesus.