# System.io operations

**URL:** <https://www.ruby-forum.com/t/system-io-operations/145609>\
**Category:** Rails\
**Created:** [August 12, 2008, 1:55am UTC](https://www.ruby-forum.com/t/system-io-operations/145609 "2008-08-12T01:55:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sohdubom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sohdubom](https://www.ruby-forum.com/u/sohdubom)\
**Post date:** [August 12, 2008, 1:55am UTC](https://www.ruby-forum.com/t/system-io-operations/145609/1 "2008-08-12T01:55:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sohdubom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sohdubom](https://www.ruby-forum.com/u/sohdubom)\
**Post date:** [August 12, 2008, 7:51am UTC](https://www.ruby-forum.com/t/system-io-operations/145609/2 "2008-08-12T07:51:34Z")

</div>

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](http://www.ruby-doc.org/core/classes/File.html)

---

<div class="post-metadata">

**Author:** ![sohdubom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dfb087/32.png) [@sohdubom](https://www.ruby-forum.com/u/sohdubom)\
**Post date:** [August 12, 2008, 7:52am UTC](https://www.ruby-forum.com/t/system-io-operations/145609/3 "2008-08-12T07:52:14Z")

</div>

Matt Haley wrote:

> [http://www.ruby-doc.org/core/classes/File.html](http://www.ruby-doc.org/core/classes/File.html)

Er, [class File - RDoc Documentation](http://www.ruby-doc.org/core/classes/File.html)
