Outputting file sizes of each item in a directory (error)

F

Feng Tien

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
============
 

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,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top