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.

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