# Re: simple get file by filename

**URL:** <https://www.ruby-forum.com/t/re-simple-get-file-by-filename/113891>\
**Category:** Ruby\
**Created:** [September 5, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/re-simple-get-file-by-filename/113891 "2007-09-05T23:03:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [September 5, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/re-simple-get-file-by-filename/113891/1 "2007-09-05T23:03:16Z")

</div>

A regular expression will do just fine.

entries.each do |entry|  
puts entry if entry =~ /^jpg\_image/  
end

----- Original Message ----  
From: eggie5 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: ruby-talk ML [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Wednesday, September 5, 2007 2:55:07 PM  
Subject: simple get file by filename

Consider this:

I have a list of files that I get by calling:

Dir.entries(“/”)

I just want to search this list and match the file name that matches  
1\_1.\* ( i.e. the filename without the extension)

So, for example, If the pattern to match against the list was  
“jpg\_image.” it should return the filename “jpg\_image.jpg” (assuming  
the file exists).

What’s the most succinct way to do this in ruby?
