How distinguish between a file and a directory?

A newbie question. The code

    Dir.foreach(Dir.getwd) do |f|
      if ((f != '.') && (f != '..'))
        puts f
      end
    end

lists the files and directories in the current working directory but does not identify which is a file and which is a directory. How can I add that information to the listing? Thanks.

File::directory?(path)
will return true of name is a directory, false if it is a file

Farrel

Dir['*'].each do |f|
  print "#{f} is a: "
  if File.directory?(f)
    puts "directory"
  else
    puts "file"
  end
end

Please note that Dir:: is an alias to Dir::glob and it will not show
you files starting with a dot unless you use Dir['{,.}*']

^ manveru

···

On 10/17/07, Bazsl <hs@dbginc.com> wrote:

A newbie question. The code

    Dir.foreach(Dir.getwd) do |f|
      if ((f != '.') && (f != '..'))
        puts f
      end
    end

lists the files and directories in the current working directory but
does not identify which is a file and which is a directory. How can I
add that information to the listing? Thanks.