# How distinguish between a file and a directory?

**URL:** <https://rubytalk.org/t/how-distinguish-between-a-file-and-a-directory/41432>\
**Category:** ruby-talk\
**Created:** [16 October 2007 15:09 UTC](https://rubytalk.org/t/how-distinguish-between-a-file-and-a-directory/41432 "2007-10-16T15:09:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Riddle](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Allen\_Riddle](https://rubytalk.org/u/Allen_Riddle)\
**Post date:** [16 October 2007 15:09 UTC](https://rubytalk.org/t/how-distinguish-between-a-file-and-a-directory/41432/1 "2007-10-16T15:09:40Z")

</div>

There are class side methods called "file?" and "directory?" on the File  
class that you can use. (ex. File.directory?("path/to/directory") )

> **···**
>
> -----Original Message-----  
> From: Bazsl [[mailto:hs@dbginc.com](mailto:hs@dbginc.com)]  
> Sent: Tuesday, October 16, 2007 10:01 AM  
> To: ruby-talk ML  
> Subject: How distinguish between a file and a directory?
> 
> A newbie question. The code
> 
> &nbsp;&nbsp;&nbsp;&nbsp;Dir.foreach(Dir.getwd) do |f|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((f != '.') && (f != '..'))  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts f  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;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.
