# Gotcha for Newbies

**URL:** <https://www.ruby-forum.com/t/gotcha-for-newbies/100512>\
**Category:** Ruby\
**Created:** [February 3, 2006, 2:56am UTC](https://www.ruby-forum.com/t/gotcha-for-newbies/100512 "2006-02-03T02:56:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neowulf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@Neowulf](https://www.ruby-forum.com/u/Neowulf)\
**Post date:** [February 3, 2006, 2:56am UTC](https://www.ruby-forum.com/t/gotcha-for-newbies/100512/1 "2006-02-03T02:56:06Z")

</div>

Hi all,

I just thought I’d drop this one in for any newbie’s playing around  
with directory listings…

me@somehost\> find /somedir \> results

File.open("./results").each do |file|  
puts file unless File.directory(file)  
end

… What do we think the output should be if given that /somedir  
contains both directories and files…

And why does this give you a different result…

require ‘find’

Find.find("./results").each do |file|  
puts file unless File.directory(file)  
end

Yep… probably _extrememly_ obvious to the oldtimers… but drove me  
nuts…\n

~Neowulf

Hint: …chomp…

---

<div class="post-metadata">

**Author:** ![Neowulf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c4cdca/32.png) [@Neowulf](https://www.ruby-forum.com/u/Neowulf)\
**Post date:** [February 3, 2006, 3:05am UTC](https://www.ruby-forum.com/t/gotcha-for-newbies/100512/2 "2006-02-03T03:05:09Z")

</div>

Opps… correction…

require ‘find’

Find.find("./somedir").each do |file|  
puts file unless File.directory(file)  
end

~Neowulf
