# Find an element in an array

**URL:** <https://www.ruby-forum.com/t/find-an-element-in-an-array/144942>\
**Category:** Rails\
**Created:** [August 4, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/find-an-element-in-an-array/144942 "2008-08-04T15:48:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![billv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@billv](https://www.ruby-forum.com/u/billv)\
**Post date:** [August 4, 2008, 3:48pm UTC](https://www.ruby-forum.com/t/find-an-element-in-an-array/144942/1 "2008-08-04T15:48:16Z")

</div>

Hi,

I have a very basic question: How can I check to see if an array  
includes a certain type of element.

Specifically, I an creating an array of file names from a directory on  
the server. I then want to identify which items in the array meet a  
certain pattern. In my controller I have:

```
@files=Dir.entries("/home/bill/PDF")
render :action => "index", :layout => "visions"

```

In my view I have:

\<% for x in @files %\>  
\<%= link\_to x, :action =\> :show\_pdf, :value =\> x %\>  
  
\<% end %\>

In this case, all entries from the directory at listed. I would like  
to restrict the links to only those files with a “.pdf” extension. I  
assume I need to use regular expression code here, but I don’t know  
how to do that in this case.

Thanks.

---

<div class="post-metadata">

**Author:** ![billv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bb73d2/32.png) [@billv](https://www.ruby-forum.com/u/billv)\
**Post date:** [August 4, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/find-an-element-in-an-array/144942/2 "2008-08-04T15:58:15Z")

</div>

Try the Dir.glob method:  
@files = Dir.glob("/home/bill/PDF/\*.pdf")

Regards

billv  
escribió:\> Hi,
