On 13 Nov 2007, at 14:59, Feng Tien wrote:

> code:
>
>
> Dir.foreach("bad") do |f|
> puts "#{f}: #{File.size f}"
> end
> ============
> Each filename in the directory "bad" is displayed along with the file
> size.
>
> I know the file.size works because I tried it with an static name and
> displayed fine.
>
> the error I got
>
> ============
> lib/dir_test.rb:6:in `size': No such file or directory - IMG_0964.jpg
> (Errno::ENOENT)
>  from lib/dir_test.rb:6
>  from lib/dir_test.rb:5:in `foreach'
>  from lib/dir_test.rb:5
> ============

Add 'bad/' to each filename. E.g:

Dir.foreach("bad") do |f|
   puts "#{f}: #{File.size('bad/'+f)}"
end

Alex Gutteridge

Bioinformatics Center
Kyoto University