# Finding files in a directory and regexp

**URL:** <https://www.ruby-forum.com/t/finding-files-in-a-directory-and-regexp/99742>\
**Category:** Ruby\
**Created:** [July 25, 2006, 7:54am UTC](https://www.ruby-forum.com/t/finding-files-in-a-directory-and-regexp/99742 "2006-07-25T07:54:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexanderl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@alexanderl](https://www.ruby-forum.com/u/alexanderl)\
**Post date:** [July 25, 2006, 7:54am UTC](https://www.ruby-forum.com/t/finding-files-in-a-directory-and-regexp/99742/1 "2006-07-25T07:54:14Z")

</div>

Hello,

I am doing something like this:

```
Find.find("/Users/alamb/_Current-Work/fiches") do |path|
  if(path =~ /100_/)
	...

```

In order to get all the files of the directory which have “100\_” in  
the name.

Two questions:

1. Is there a way to use the find method to directly achieve this?
2. I tried a Regexp with /^100\_/ to say "files starting with ‘100\_’  
" but it doensn’t seem to work.

Any idea?

## Thanks

Alexander L.  
Service d’Informatique MÃ©dicale  
HÃ´pitaux Universitaires de GenÃ¨ve  
removed\_email\_address@domain.invalid  
+41 22 372 88 62  
+41 79 420 79 73

---

<div class="post-metadata">

**Author:** ![alexanderl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@alexanderl](https://www.ruby-forum.com/u/alexanderl)\
**Post date:** [July 25, 2006, 8:03am UTC](https://www.ruby-forum.com/t/finding-files-in-a-directory-and-regexp/99742/2 "2006-07-25T08:03:49Z")

</div>

Alexander L. wrote:

> Two questions:
> 
> 1. Is there a way to use the find method to directly achieve this?
> 2. I tried a Regexp with /^100\_/ to say "files starting with ‘100\_’ "  
> but it doensn’t seem to work.

I don’t usually use Find… Dir is fairly powerful.

Dir[“100\*”] # all 100-type files in current dir  
Dir["\*\*/100\*"] # all in this tree (correct syntax??)

Hal

---

<div class="post-metadata">

**Author:** ![alexanderl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f0a364/32.png) [@alexanderl](https://www.ruby-forum.com/u/alexanderl)\
**Post date:** [July 27, 2006, 7:51am UTC](https://www.ruby-forum.com/t/finding-files-in-a-directory-and-regexp/99742/3 "2006-07-27T07:51:35Z")

</div>

One could use Rio ([rio.rubyforge.org](http://rio.rubyforge.org))

This would find the files which start with ‘100\_’

rio("/Users/alamb/_Current-Work/fiches").files(/^100_/) do |path|  
…  
end

To include files in subdirectories that start with ‘100\_’ use:

rio("/Users/alamb/_Current-Work/fiches").all.files(/^100_/) do |path|  
…  
end
