System.io operations

hi.

@things = Dir.glob(’*’)

the code above returns all elements inside the particular directory.
those elements can be either a folder name or a file name. i could loop
through @things and output the names like:

<% for thing in @things -%>
thing name is: <%= thing %>

<% end %>

but instead i´d like to know whether these things are files or folders,
so

<% for thing in @things -%>
<% if thing.file? %>
file name is: <%= thing %>

<% else %>
dir name is: <%= thing %>

<% end %>
<% end %>

of course the code above doesn´t work. the doubt is how i can find out
whether it´s a file or a folder?

Soh D. wrote:

of course the code above doesn´t work. the doubt is how i can find out
whether it´s a file or a folder?

You want to call `File.directory?’.

http://www.ruby-doc.org/core/classes/File.html

Matt Haley wrote:

http://www.ruby-doc.org/core/classes/File.html

Er, http://www.ruby-doc.org/core/classes/File.html

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs