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

Discussion in 'Ruby' started by Feng Tien, Nov 13, 2007.

  1. Feng Tien

    Feng Tien Guest

    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
    ============
    --
    Posted via http://www.ruby-forum.com/.
     
    Feng Tien, Nov 13, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. donbro
    Replies:
    2
    Views:
    545
    donbro
    Nov 1, 2005
  2. Ned Balzer

    Error in IE outputting to Excel

    Ned Balzer, Dec 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    294
    Ned Balzer
    Dec 12, 2006
  3. Replies:
    3
    Views:
    334
    Fredrik Lundh
    Oct 30, 2006
  4. Jeffrey Ellin

    Getting directory sizes on win32

    Jeffrey Ellin, Sep 3, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    419
    Jay Tilton
    Sep 4, 2003
  5. Zebee Johnstone

    finding directory sizes

    Zebee Johnstone, Aug 23, 2004, in forum: Perl Misc
    Replies:
    11
    Views:
    191
    Darren Dunham
    Aug 26, 2004
Loading...

Share This Page