# Find

**URL:** <https://www.ruby-forum.com/t/find/116571>\
**Category:** Ruby\
**Created:** [October 7, 2007, 2:42pm UTC](https://www.ruby-forum.com/t/find/116571 "2007-10-07T14:42:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 7, 2007, 2:42pm UTC](https://www.ruby-forum.com/t/find/116571/1 "2007-10-07T14:42:21Z")

</div>

Hi,

the Ruby built-in Find module lacks a lot of features the  
GNU find tools has. I wrote a new one (~170 lines).

[http://www.bertram-scharpf.de/tmp/find.rb](http://www.bertram-scharpf.de/tmp/find.rb)

Maybe somebody likes it.

Bertram

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 7, 2007, 3:32pm UTC](https://www.ruby-forum.com/t/find/116571/2 "2007-10-07T15:32:21Z")

</div>

On Oct 7, 6:41 am, Bertram S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> the Ruby built-in Find module lacks a lot of features the  
> GNU find tools has. I wrote a new one (~170 lines).
> 
> [http://www.bertram-scharpf.de/tmp/find.rb](http://www.bertram-scharpf.de/tmp/find.rb)
> 
> Maybe somebody likes it.

I wrote file-find not long ago:

[http://raa.ruby-lang.org/project/file-find/](http://raa.ruby-lang.org/project/file-find/)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 7, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/find/116571/3 "2007-10-07T23:19:03Z")

</div>

On Sun, 7 Oct 2007, Daniel B. wrote:

> > Maybe somebody likes it.
> 
> I wrote file-find not long ago:
> 
> [http://raa.ruby-lang.org/project/file-find/](http://raa.ruby-lang.org/project/file-find/)

Time to merge stuff into Ruby proper if so many (…) people see the  
need  
to improve the aparently meager features of the built-in find?  
\*t

–

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 8, 2007, 4:12am UTC](https://www.ruby-forum.com/t/find/116571/4 "2007-10-08T04:12:49Z")

</div>

Tomas P.'s Mailing L. wrote:

> > > [http://www.bertram-scharpf.de/tmp/find.rb](http://www.bertram-scharpf.de/tmp/find.rb)
> 
> ## –
> 
> ## Tomas P. [http://sourcepole.com](http://sourcepole.com) - Linux & Open Source Solutions

As long as it doesn’t get more bigger and fatter then GNU Find is…

Then I’d be happy 🙂

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 8, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/find/116571/5 "2007-10-08T13:35:56Z")

</div>

> > > [http://raa.ruby-lang.org/project/file-find/](http://raa.ruby-lang.org/project/file-find/)

Both seem complementary. Bertram has sorting built-in and is not  
backwards compatible.

After a quick look, Bertram’s code also has silly inefficient things  
like:  
dir = (Dir.open @fullpath do |d| d.entries end) - SPECIAL\_DIRS  
which can just be:  
dir = Dir.entries(@fullpath) - SPECIAL\_DIRS  
and the Etc module may be checked several times depending on what you  
request.

Daniel’s has searching based on different much more rich criteria and  
also breaks backwards compatibility. It lacks sorting and the docs  
lack simple examples. I did not check the code yet.

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 8, 2007, 4:16am UTC](https://www.ruby-forum.com/t/find/116571/6 "2007-10-08T04:16:54Z")

</div>

On Oct 7, 3:17 pm, Tomas P.'s Mailing L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > Maybe somebody likes it.
> 
> > I wrote file-find not long ago:
> 
> > [http://raa.ruby-lang.org/project/file-find/](http://raa.ruby-lang.org/project/file-find/)
> 
> Time to merge stuff into Ruby proper if so many (…) people see the need  
> to improve the aparently meager features of the built-in find?  
> \*t

My experience on ruby-core tells me that the odds of getting the  
radical changes we would want into the stdlib are about nil unless  
there’s a general outcry.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 8, 2007, 1:57pm UTC](https://www.ruby-forum.com/t/find/116571/7 "2007-10-08T13:57:41Z")

</div>

Hi,

Am Montag, 08. Okt 2007, 20:35:04 +0900 schrieb gga:

> > >
> 
> dir = Dir.entries(@fullpath) - SPECIAL\_DIRS  
> Argh!

> and the Etc module may be checked several times depending on what you  
> request.

I already corrected this yesterday and upload it now.

Bertram

---

<div class="post-metadata">

**Author:** ![Bertram\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/54ee81/32.png) [@Bertram\_S](https://www.ruby-forum.com/u/Bertram_S)\
**Post date:** [October 8, 2007, 4:28pm UTC](https://www.ruby-forum.com/t/find/116571/8 "2007-10-08T16:28:53Z")

</div>

On Oct 7, 2007, at 6:41 AM, Bertram S. wrote:

> Hi,
> 
> the Ruby built-in Find module lacks a lot of features the  
> GNU find tools has. I wrote a new one (~170 lines).
> 
> [http://www.bertram-scharpf.de/tmp/find.rb](http://www.bertram-scharpf.de/tmp/find.rb)
> 
> Maybe somebody likes it.

this is one of the very smallest directories i am working with:

[cfadmin@yacht cfadmin]$ find /mnt/yacht0/data/night\_files/|wc -l  
69287

[cfadmin@yacht cfadmin]$ ruby a.rb  
user system total real  
bertram.scharpf.find 2.140000 1.230000 3.370000 ( 7.602333)  
alib.util.find 1.360000 0.440000 1.800000 ( 1.812519)

[cfadmin@yacht cfadmin]$ cat a.rb  
require ‘benchmark’  
require ‘alib’  
require ‘bertram.scharpf.find.rb’

top = ‘/mnt/yacht0/data/night\_files/’

Benchmark.bm do |b|  
b.report(‘bertram.scharpf.find’){ Find.open(top){|x|} }  
b.report(‘alib.util.find’){ alib.util.find(top){|x|} }  
end

also there is alib.util.find2 which yields the stat together with the  
path, preventing and extra stat on the pathname. in practice doing  
something like

def method\_missing m, \*a, &b  
stat.send m, \*a, &b  
end

means you have to use a ton of code since it’s possible that

f.size ### no error  
f.mtime ### ENOENT

btw mine

[http://codeforpeople.com/lib/ruby/alib/alib-0.5.0/lib/alib-0.5.0/](http://codeforpeople.com/lib/ruby/alib/alib-0.5.0/lib/alib-0.5.0/)  
find2.rb

isn’t a spectacular implementation, it is based on Motoyuki  
Kasahara’s 2001 lib, which used to be on the raa, called find2 - but  
it’s reasonably fast, does depth and breath, caches stats, and  
handles files evaporation from the filesystem or not being accessible  
due to permissions errors.

i think all these libraries prove that a new find mechanism needs to  
be incorporated into the stdlib! we should take the best features  
from all the various libs and propose a new library that is backward  
compatible with the built-in find.

kind regards.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)
